src/BDSOctupole.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 be the BDSGlobal version
00008 */
00009 
00010 #include "BDSGlobalConstants.hh" 
00011 
00012 #include "BDSOctupole.hh"
00013 #include "G4Box.hh"
00014 #include "G4Tubs.hh"
00015 #include "G4VisAttributes.hh"
00016 #include "G4LogicalVolume.hh"
00017 #include "G4VPhysicalVolume.hh"
00018 #include "G4UserLimits.hh"
00019 #include "G4TransportationManager.hh"
00020 
00021 #include <map>
00022 
00023 //============================================================
00024 
00025 typedef std::map<G4String,int> LogVolCountMap;
00026 extern LogVolCountMap* LogVolCount;
00027 
00028 typedef std::map<G4String,G4LogicalVolume*> LogVolMap;
00029 extern LogVolMap* LogVol;
00030 
00031 //============================================================
00032 
00033 BDSOctupole::BDSOctupole(G4String aName, G4double aLength, 
00034                          G4double bpRad, G4double FeRad,
00035                          G4double BTrpPrime, G4double tilt, 
00036                          G4double outR, 
00037                          std::list<G4double> blmLocZ, std::list<G4double> blmLocTheta,
00038                          G4String aTunnelMaterial, G4String aMaterial):
00039   BDSMultipole(aName, aLength, bpRad, FeRad, SetVisAttributes(), blmLocZ, blmLocTheta, aTunnelMaterial, aMaterial),
00040   itsBTrpPrime(BTrpPrime),
00041   itsStepper(NULL),itsMagField(NULL),itsEqRhs(NULL)
00042 {
00043   SetOuterRadius(outR);
00044   itsTilt=tilt;
00045   itsType="octu";
00046 
00047   if (!(*LogVolCount)[itsName])
00048     {
00049       //
00050       // build external volume
00051       //
00052       BuildDefaultMarkerLogicalVolume();
00053 
00054       //
00055       //build tunnel
00056       //
00057       if(BDSGlobalConstants::Instance()->GetBuildTunnel()){
00058         BuildTunnel();
00059       }
00060 
00061       //
00062       // build beampipe (geometry + magnetic field)
00063       //
00064       BuildBPFieldAndStepper();
00065       BuildBPFieldMgr(itsStepper,itsMagField);
00066       BuildBeampipe();
00067 
00068       //
00069       // build magnet (geometry + magnetic field)
00070       //
00071       BuildDefaultOuterLogicalVolume(itsLength);
00072       if(BDSGlobalConstants::Instance()->GetIncludeIronMagFields())
00073         {
00074           G4double polePos[4];
00075           G4double Bfield[3];
00076 
00077           //coordinate in GetFieldValue
00078           polePos[0]=-BDSGlobalConstants::Instance()->GetMagnetPoleRadius()*sin(pi/8);
00079           polePos[1]=BDSGlobalConstants::Instance()->GetMagnetPoleRadius()*cos(pi/8);
00080           polePos[2]=0.;
00081           polePos[3]=-999.;//flag to use polePos rather than local track
00082 
00083           itsMagField->GetFieldValue(polePos,Bfield);
00084           G4double BFldIron=
00085             sqrt(Bfield[0]*Bfield[0]+Bfield[1]*Bfield[1])*
00086             BDSGlobalConstants::Instance()->GetMagnetPoleSize()/
00087             (BDSGlobalConstants::Instance()->GetComponentBoxSize()/2-
00088              BDSGlobalConstants::Instance()->GetMagnetPoleRadius());
00089 
00090           // Magnetic flux from a pole is divided in two directions
00091           BFldIron/=2.;
00092 
00093           BuildOuterFieldManager(8, BFldIron,pi/8);
00094         }
00095 
00096       //Build the beam loss monitors
00097       BuildBLMs();
00098 
00099       //
00100       // define sensitive volumes for hit generation
00101       //
00102       if(BDSGlobalConstants::Instance()->GetSensitiveBeamPipe()){
00103         SetMultipleSensitiveVolumes(itsBeampipeLogicalVolume);
00104       }
00105       if(BDSGlobalConstants::Instance()->GetSensitiveComponents()){
00106         SetMultipleSensitiveVolumes(itsOuterLogicalVolume);
00107       }
00108 
00109       //
00110       // set visualization attributes
00111       //
00112       itsVisAttributes=SetVisAttributes();
00113       itsVisAttributes->SetForceSolid(true);
00114       itsOuterLogicalVolume->SetVisAttributes(itsVisAttributes);
00115 
00116       //
00117       // append marker logical volume to volume map
00118       //
00119       (*LogVolCount)[itsName]=1;
00120       (*LogVol)[itsName]=itsMarkerLogicalVolume;
00121     }
00122   else
00123     {
00124       (*LogVolCount)[itsName]++;
00125       if(BDSGlobalConstants::Instance()->GetSynchRadOn()&& BDSGlobalConstants::Instance()->GetSynchRescale())
00126         {
00127           // with synchrotron radiation, the rescaled magnetic field
00128           // means elements with the same name must have different
00129           //logical volumes, becuase they have different fields
00130           itsName+=BDSGlobalConstants::Instance()->StringFromInt((*LogVolCount)[itsName]);
00131 
00132           //
00133           // build external volume
00134           // 
00135           BuildDefaultMarkerLogicalVolume();
00136 
00137           //
00138           // build beampipe (geometry + magnetic field)
00139           //
00140           BuildBPFieldAndStepper();
00141           BuildBPFieldMgr(itsStepper,itsMagField);
00142           BuildBeampipe();
00143 
00144           //
00145           // build magnet (geometry + magnetic field)
00146           //
00147           BuildDefaultOuterLogicalVolume(itsLength);
00148           if(BDSGlobalConstants::Instance()->GetIncludeIronMagFields())
00149             {
00150               G4double polePos[4];
00151               G4double Bfield[3];
00152               
00153               //coordinate in GetFieldValue
00154               polePos[0]=-BDSGlobalConstants::Instance()->GetMagnetPoleRadius()*sin(pi/8);
00155               polePos[1]=BDSGlobalConstants::Instance()->GetMagnetPoleRadius()*cos(pi/8);
00156               polePos[2]=0.;
00157               polePos[3]=-999.;//flag to use polePos rather than local track
00158 
00159               itsMagField->GetFieldValue(polePos,Bfield);
00160               G4double BFldIron=
00161                 sqrt(Bfield[0]*Bfield[0]+Bfield[1]*Bfield[1])*
00162                 BDSGlobalConstants::Instance()->GetMagnetPoleSize()/
00163                 (BDSGlobalConstants::Instance()->GetComponentBoxSize()/2-
00164                  BDSGlobalConstants::Instance()->GetMagnetPoleRadius());
00165 
00166               // Magnetic flux from a pole is divided in two directions
00167               BFldIron/=2.;
00168               
00169               BuildOuterFieldManager(8, BFldIron,pi/8);
00170             }
00171           //When is SynchRescale(factor) called?
00172 
00173           //
00174           // define sensitive volumes for hit generation
00175           //
00176           if(BDSGlobalConstants::Instance()->GetSensitiveBeamPipe()){
00177             SetSensitiveVolume(itsBeampipeLogicalVolume);
00178           }
00179           if(BDSGlobalConstants::Instance()->GetSensitiveComponents()){
00180             SetSensitiveVolume(itsOuterLogicalVolume);
00181           }
00182           //
00183           // set visualization attributes
00184           //
00185           itsVisAttributes=SetVisAttributes();
00186           itsVisAttributes->SetForceSolid(true);
00187           itsOuterLogicalVolume->SetVisAttributes(itsVisAttributes);
00188           
00189           //
00190           // append marker logical volume to volume map
00191           //
00192           (*LogVol)[itsName]=itsMarkerLogicalVolume;
00193         }
00194       else
00195         {
00196           //
00197           // use already defined marker volume
00198           //
00199           itsMarkerLogicalVolume=(*LogVol)[itsName];
00200         }      
00201     }
00202 }
00203 
00204 void BDSOctupole::SynchRescale(G4double factor)
00205 {
00206   itsStepper->SetBTrpPrime(factor*itsBTrpPrime);
00207   itsMagField->SetBTrpPrime(factor*itsBTrpPrime);
00208 #ifdef DEBUG
00209   G4cout << "Oct " << itsName << " has been scaled" << G4endl;
00210 #endif
00211 }
00212 
00213 G4VisAttributes* BDSOctupole::SetVisAttributes()
00214 {
00215   itsVisAttributes=new G4VisAttributes(G4Colour(0,1,1));
00216   return itsVisAttributes;
00217 }
00218 
00219 void BDSOctupole::BuildBPFieldAndStepper()
00220 {
00221   // set up the magnetic field and stepper
00222   itsMagField=new BDSOctMagField(itsBTrpPrime);
00223   itsEqRhs=new G4Mag_UsualEqRhs(itsMagField);
00224   
00225   itsStepper=new BDSOctStepper(itsEqRhs);
00226   itsStepper->SetBTrpPrime(itsBTrpPrime);
00227 }
00228 
00229 BDSOctupole::~BDSOctupole()
00230 {
00231   delete itsVisAttributes;
00232   delete itsMagField;
00233   delete itsEqRhs;
00234   delete itsStepper;
00235 }

Generated on 27 Aug 2013 for BDSIM by  doxygen 1.4.7