CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/MagneticField/VolumeBasedEngine/src/VolumeBasedMagneticField.cc

Go to the documentation of this file.
00001 #include "MagneticField/VolumeBasedEngine/interface/VolumeBasedMagneticField.h"
00002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00003 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
00004 
00005 VolumeBasedMagneticField::VolumeBasedMagneticField( const edm::ParameterSet& config,
00006                                                     std::vector<MagBLayer *> theBLayers,
00007                                                     std::vector<MagESector *> theESectors,
00008                                                     std::vector<MagVolume6Faces*> theBVolumes,
00009                                                     std::vector<MagVolume6Faces*> theEVolumes, 
00010                                                     float rMax, float zMax, 
00011                                                     const MagneticField* param,
00012                                                     bool isParamFieldOwned) : 
00013   field(new MagGeometry(config,theBLayers,theESectors,theBVolumes,theEVolumes)), 
00014   maxR(rMax),
00015   maxZ(zMax),
00016   paramField(param),
00017   magGeomOwned(true),
00018   paramFieldOwned(isParamFieldOwned)
00019 {}
00020 
00021 
00022 VolumeBasedMagneticField::VolumeBasedMagneticField(const VolumeBasedMagneticField& vbf) : 
00023   field(vbf.field),
00024   maxR(vbf.maxR),
00025   maxZ(vbf.maxZ),
00026   paramField(vbf.paramField),
00027   magGeomOwned(false),
00028   paramFieldOwned(false) {
00029   // std::cout << "VolumeBasedMagneticField::clone() (shallow copy)" << std::endl;
00030 }
00031 
00032 
00033 MagneticField* VolumeBasedMagneticField::clone() const {
00034   return new VolumeBasedMagneticField(*this);
00035 }
00036 
00037 
00038 VolumeBasedMagneticField::~VolumeBasedMagneticField(){
00039   if(magGeomOwned) delete field;
00040   if(paramFieldOwned) delete paramField;
00041 }
00042 
00043 GlobalVector VolumeBasedMagneticField::inTesla (const GlobalPoint& gp) const {
00044 
00045   // If parametrization of the inner region is available, use it.
00046   if (paramField && paramField->isDefined(gp)) return paramField->inTeslaUnchecked(gp);
00047 
00048   // If point is outside magfield map, return 0 field (not an error)
00049   if (!isDefined(gp))  return GlobalVector();
00050 
00051   return field->fieldInTesla(gp);
00052 }
00053 
00054 GlobalVector VolumeBasedMagneticField::inTeslaUnchecked(const GlobalPoint& gp) const{
00055   //same as above, but do not check range
00056   if (paramField && paramField->isDefined(gp)) return paramField->inTeslaUnchecked(gp);
00057   return field->fieldInTesla(gp);
00058 }
00059 
00060 
00061 const MagVolume * VolumeBasedMagneticField::findVolume(const GlobalPoint & gp) const
00062 {
00063   return field->findVolume(gp);
00064 }
00065 
00066 
00067 bool VolumeBasedMagneticField::isDefined(const GlobalPoint& gp) const {
00068   return (fabs(gp.z()) < maxZ && gp.perp() < maxR);
00069 }
00070 
00071 
00072 bool VolumeBasedMagneticField::isZSymmetric() const {
00073   return field->isZSymmetric();
00074 }