CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/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   theNominalValue = MagneticField::nominalValue();
00021 }
00022 
00023 
00024 VolumeBasedMagneticField::VolumeBasedMagneticField(const VolumeBasedMagneticField& vbf) : 
00025   field(vbf.field),
00026   maxR(vbf.maxR),
00027   maxZ(vbf.maxZ),
00028   paramField(vbf.paramField),
00029   magGeomOwned(false),
00030   paramFieldOwned(false),
00031   theNominalValue(vbf.theNominalValue) {
00032   // std::cout << "VolumeBasedMagneticField::clone() (shallow copy)" << std::endl;
00033 }
00034 
00035 
00036 MagneticField* VolumeBasedMagneticField::clone() const {
00037   return new VolumeBasedMagneticField(*this);
00038 }
00039 
00040 
00041 VolumeBasedMagneticField::~VolumeBasedMagneticField(){
00042   if(magGeomOwned) delete field;
00043   if(paramFieldOwned) delete paramField;
00044 }
00045 
00046 GlobalVector VolumeBasedMagneticField::inTesla (const GlobalPoint& gp) const {
00047 
00048   // If parametrization of the inner region is available, use it.
00049   if (paramField && paramField->isDefined(gp)) return paramField->inTeslaUnchecked(gp);
00050 
00051   // If point is outside magfield map, return 0 field (not an error)
00052   if (!isDefined(gp))  return GlobalVector();
00053 
00054   return field->fieldInTesla(gp);
00055 }
00056 
00057 GlobalVector VolumeBasedMagneticField::inTeslaUnchecked(const GlobalPoint& gp) const{
00058   //same as above, but do not check range
00059   if (paramField && paramField->isDefined(gp)) return paramField->inTeslaUnchecked(gp);
00060   return field->fieldInTesla(gp);
00061 }
00062 
00063 
00064 const MagVolume * VolumeBasedMagneticField::findVolume(const GlobalPoint & gp) const
00065 {
00066   return field->findVolume(gp);
00067 }
00068 
00069 
00070 bool VolumeBasedMagneticField::isDefined(const GlobalPoint& gp) const {
00071   return (fabs(gp.z()) < maxZ && gp.perp() < maxR);
00072 }
00073 
00074 
00075 bool VolumeBasedMagneticField::isZSymmetric() const {
00076   return field->isZSymmetric();
00077 }