/home/cern/BDSIM_new/src/BDSSolenoid.cc

00001 //  
00002 //   BDSIM, (C) 2001-2007
00003 //   
00004 //   version 0.4
00005 //  
00006 //
00007 //
00008 //   Solenoid class
00009 //
00010 //
00011 //   History
00012 //
00013 //     21 Oct 2007 by Marchiori,  v.0.4
00014 //
00015 //
00016 
00017 
00018 #include "BDSGlobalConstants.hh" // must be first in include list
00019 
00020 #include "BDSSolenoid.hh"
00021 #include "G4Mag_UsualEqRhs.hh"
00022 #include "BDSSolenoidMagField.hh"
00023 #include "G4MagneticField.hh"
00024 #include "BDSSolenoidStepper.hh"
00025 #include "G4HelixImplicitEuler.hh"
00026 
00027 #include "G4Box.hh"
00028 #include "G4Tubs.hh"
00029 #include "G4VisAttributes.hh"
00030 #include "G4LogicalVolume.hh"
00031 #include "G4VPhysicalVolume.hh"
00032 #include "G4UserLimits.hh"
00033 #include "G4TransportationManager.hh"
00034 #include <map>
00035 
00036 const int DEBUG = 0;
00037 
00038 //============================================================
00039 
00040 typedef std::map<G4String,int> LogVolCountMap;
00041 extern LogVolCountMap* LogVolCount;
00042 
00043 typedef std::map<G4String,G4LogicalVolume*> LogVolMap;
00044 extern LogVolMap* LogVol;
00045 
00046 extern BDSMaterials* theMaterials;
00047 //============================================================
00048 
00049 BDSSolenoid::BDSSolenoid(G4String aName, G4double aLength, 
00050                          G4double bpRad, G4double FeRad,
00051                          G4double bField, G4double outR,
00052                          G4String aMaterial, G4String spec):
00053   BDSMultipole(aName, aLength, bpRad, FeRad, SetVisAttributes(), aMaterial),
00054   itsBField(bField)
00055 {
00056   SetOuterRadius(outR);
00057   itsType="solenoid";
00058  
00059   if(DEBUG) G4cout<<"BDSSOLENOID : SPEC : "<<spec<<G4endl;
00060 
00061   if (!(*LogVolCount)[itsName])
00062     {
00063       //
00064       // build external volume
00065       // 
00066       BuildDefaultMarkerLogicalVolume();
00067 
00068       //
00069       // build beampipe (geometry + magnetic field)
00070       //
00071       BuildBPFieldAndStepper();
00072       BuildBPFieldMgr(itsStepper,itsMagField);
00073       BuildBeampipe(itsLength);
00074 
00075       //
00076       // build magnet (geometry + magnetic field)
00077       //
00078       BuildDefaultOuterLogicalVolume(itsLength);
00079       if(BDSGlobals->GetIncludeIronMagFields())
00080         {
00081           G4cerr<<"IncludeIronMagFields option not implemented for solenoid class"<<G4endl;
00082         }
00083 
00084       //
00085       // define sensitive volumes for hit generation
00086       //
00087       SetMultipleSensitiveVolumes(itsBeampipeLogicalVolume);
00088       SetMultipleSensitiveVolumes(itsOuterLogicalVolume);
00089 
00090       //
00091       // set visualization attributes
00092       //
00093       itsVisAttributes=SetVisAttributes();
00094       itsVisAttributes->SetForceSolid(true);
00095       itsOuterLogicalVolume->SetVisAttributes(itsVisAttributes);
00096 
00097       //
00098       // append marker logical volume to volume map
00099       //
00100       (*LogVolCount)[itsName]=1;
00101       (*LogVol)[itsName]=itsMarkerLogicalVolume;
00102     }
00103   else
00104     {
00105       (*LogVolCount)[itsName]++;
00106       if(BDSGlobals->GetSynchRadOn()&& BDSGlobals->GetSynchRescale())
00107         {
00108           // with synchrotron radiation, the rescaled magnetic field
00109           // means elements with the same name must have different
00110           //logical volumes, becuase they have different fields
00111           itsName+=BDSGlobals->StringFromInt((*LogVolCount)[itsName]);
00112 
00113           //
00114           // build external volume
00115           // 
00116           BuildDefaultMarkerLogicalVolume();
00117 
00118           //
00119           // build beampipe (geometry + magnetic field)
00120           //
00121           BuildBPFieldAndStepper();
00122           BuildBPFieldMgr(itsStepper,itsMagField);
00123           BuildBeampipe(itsLength);
00124 
00125           //
00126           // build magnet (geometry + magnetic field)
00127           //
00128           BuildDefaultOuterLogicalVolume(itsLength);
00129           if(BDSGlobals->GetIncludeIronMagFields())
00130             {
00131               G4cerr<<"IncludeIronMagFields option not implemented for solenoid class"<<G4endl;
00132             }
00133           //When is SynchRescale(factor) called?
00134 
00135           //
00136           // define sensitive volumes for hit generation
00137           //
00138           SetSensitiveVolume(itsBeampipeLogicalVolume);// for synchrotron
00139           //SetSensitiveVolume(itsOuterLogicalVolume);// for laserwire      
00140           
00141           //
00142           // set visualization attributes
00143           //
00144           itsVisAttributes=new G4VisAttributes(G4Colour(1.,0.,0.)); //red
00145           itsVisAttributes->SetForceSolid(true);
00146           itsOuterLogicalVolume->SetVisAttributes(itsVisAttributes);
00147           
00148           //
00149           // append marker logical volume to volume map
00150           //
00151           (*LogVol)[itsName]=itsMarkerLogicalVolume;
00152         }
00153       else
00154         {
00155           //
00156           // use already defined marker volume
00157           //
00158           itsMarkerLogicalVolume=(*LogVol)[itsName];
00159         }      
00160     }
00161 }
00162   
00163 void BDSSolenoid::SynchRescale(G4double factor)
00164 {
00165 #ifdef _USE_GEANT4_STEPPER_
00166   itsMagField->SetBField(factor*itsBField);
00167 #else
00168   itsStepper->SetBField(factor*itsBField);
00169   itsMagField->SetFieldValue(G4ThreeVector(0.0,0.0,factor*itsBField));
00170 #endif
00171   if(DEBUG) G4cout << "Solenoid " << itsName << " has been scaled" << G4endl;
00172 }
00173 
00174 G4VisAttributes* BDSSolenoid::SetVisAttributes()
00175 {
00176   itsVisAttributes=new G4VisAttributes(G4Colour(1.,0.,0.)); //red
00177   return itsVisAttributes;
00178 }
00179 
00180 void BDSSolenoid::BuildBPFieldAndStepper()
00181 {
00182   // set up the magnetic field and stepper
00183 
00184 #ifdef _USE_GEANT4_STEPPER_
00185   // using Geant4
00186   itsMagField = new BDSSolenoidMagField(itsBField);
00187   itsEqRhs=new G4Mag_UsualEqRhs(itsMagField);
00188   itsStepper=new G4HelixImplicitEuler(itsEqRhs);
00189 #else
00190   // using BDSIM
00191   G4ThreeVector Bfield(0.,0.,itsBField);
00192   itsMagField=new G4UniformMagField(Bfield);
00193   itsEqRhs=new G4Mag_UsualEqRhs(itsMagField);
00194   itsStepper=new BDSSolenoidStepper(itsEqRhs);
00195   itsStepper->SetBField(itsBField);
00196 #endif
00197 }
00198 
00199 BDSSolenoid::~BDSSolenoid()
00200 {
00201   delete itsVisAttributes;
00202   delete itsMarkerLogicalVolume;
00203   delete itsOuterLogicalVolume;
00204   delete itsPhysiComp;
00205   delete itsMagField;
00206   delete itsEqRhs;
00207   delete itsStepper;
00208 }

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