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

00001 #include "BDSBeamPipeInfo.hh"
00002 #include "BDSGlobalConstants.hh"
00003 #include "BDSMagnet.hh"
00004 #include "BDSMultipoleMagField.hh"
00005 #include "BDSMultipole.hh"
00006 
00007 #include "G4FieldManager.hh"
00008 #include "G4HelixImplicitEuler.hh"
00009 #include "G4SimpleRunge.hh"
00010 #include "G4LogicalVolume.hh"
00011 #include "G4Mag_UsualEqRhs.hh"
00012 #include "G4Tubs.hh"
00013 #include "G4UserLimits.hh"
00014 #include "G4VisAttributes.hh"
00015 #include "G4VPhysicalVolume.hh"
00016 
00017 class BDSTiltOffset;
00018 
00019 BDSMultipole::BDSMultipole(G4String            name,
00020                            G4double            length,
00021                            std::list<G4double> akn, // list of normal multipole strengths
00022                            // (NOT multiplied by multipole length)
00023                            std::list<G4double> aks, // list of skew multipole strengths
00024                            // (NOT multiplied by multipole length)
00025                            BDSBeamPipeInfo*    beamPipeInfo,
00026                            BDSMagnetOuterInfo  magnetOuterInfo,
00027                            BDSTiltOffset       tiltOffset):
00028   BDSMagnet(BDSMagnetType::multipole, name, length,
00029             beamPipeInfo, magnetOuterInfo, tiltOffset)
00030 {
00031   CommonConstructor(akn,aks);
00032 }
00033 
00034 void BDSMultipole::CommonConstructor(std::list<G4double> akn, std::list<G4double> aks)
00035 {
00036 #ifdef BDSDEBUG
00037   if (akn.size()>0){
00038     G4cout<<"Building multipole of order "<<akn.size()<<G4endl;
00039   } else {
00040     G4cout<<"Building multipole of order "<<aks.size()<<G4endl;
00041   }
00042 #endif
00043 
00044   //If the multipole has both skew and normal coefficients then they must have the same number of coefficients 
00045   if((akn.size() != aks.size()) && ((akn.size() >0) && (aks.size() > 0))) { G4cerr<<"ERROR : multipole skew and normal coefficients present, but to different order"<<G4endl;}
00046   if(akn.size() == 0 &&  aks.size() == 0) { G4cerr<<"ERROR : skew or normal multipole order must be greater than 0"<<G4endl; }
00047 
00048   //Check if any components are non-zero
00049   /*  
00050   G4bool fieldNonZero=false;
00051   for(std::list<double>::iterator it = akn.begin(); it != akn.end() && fieldNonZero == false; it++){
00052     if(*it != 0) fieldNonZero = true;
00053   }
00054   for(std::list<double>::iterator it = aks.begin(); it != aks.end() && fieldNonZero == false; it++){
00055     if(*it != 0) fieldNonZero = true;
00056   }
00057   */
00058 
00059   //If list of normal or skew multipole coefficients not present, create a default list containing zeroes.
00060   if (aks.size()==0){
00061     for(unsigned int i=0; i<akn.size(); i++){
00062       aks.push_back(0.0);
00063     }
00064   }
00065   if (akn.size()==0){
00066     for(unsigned int i=0; i<aks.size(); i++){
00067       akn.push_back(0.0);
00068     }
00069   }
00070 
00071   kn = akn;
00072   ks = aks;
00073 
00074 #ifdef BDSDEBUG 
00075   int order = 0;
00076   G4cout<<"M: kn={ ";
00077   std::list<double>::iterator kit;
00078   for(kit=kn.begin();kit!=kn.end();kit++)
00079     {
00080       G4cout<<(*kit)<<"m^-"<<++order<<" ";
00081     }
00082   G4cout<<"}"<<G4endl;
00083   order = 0;
00084   G4cout<<"M: ks={ ";
00085   for(kit=ks.begin();kit!=ks.end();kit++)
00086     {
00087       G4cout<<(*kit)<<"m^-"<<++order<<" ";
00088     }
00089   G4cout<<"}"<<G4endl;
00090 #endif
00091 
00092   itsOrder = kn.size();
00093 }
00094 
00095 void BDSMultipole::BuildBPFieldAndStepper()
00096 {
00097   // set up the magnetic field and stepper
00098   itsMagField = new BDSMultipoleMagField(kn,ks);
00099   itsEqRhs    = new G4Mag_UsualEqRhs(itsMagField);
00100   itsStepper  = new G4SimpleRunge(itsEqRhs);
00101 }

Generated on 28 Jun 2015 for BDSIM by  doxygen 1.4.7