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

Generated on 27 Aug 2013 for BDSIM by  doxygen 1.4.7