Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-14 02:34:03

0001 #include "MagneticField/VolumeBasedEngine/interface/VolumeBasedMagneticField.h"
0002 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
0003 
0004 VolumeBasedMagneticField::VolumeBasedMagneticField(int geomVersion,
0005                                                    const std::vector<MagBLayer*>& theBLayers,
0006                                                    const std::vector<MagESector*>& theESectors,
0007                                                    const std::vector<MagVolume6Faces*>& theBVolumes,
0008                                                    const std::vector<MagVolume6Faces*>& theEVolumes,
0009                                                    float rMax,
0010                                                    float zMax,
0011                                                    const MagneticField* param,
0012                                                    bool isParamFieldOwned)
0013     : field(new MagGeometry(geomVersion, theBLayers, theESectors, theBVolumes, theEVolumes)),
0014       maxRsq(rMax * rMax),
0015       maxZ(zMax),
0016       paramField(param),
0017       magGeomOwned(true),
0018       paramFieldOwned(isParamFieldOwned) {
0019   setNominalValue();
0020 }
0021 
0022 VolumeBasedMagneticField::VolumeBasedMagneticField(const VolumeBasedMagneticField& vbf)
0023     : MagneticField::MagneticField(vbf),
0024       field(vbf.field),
0025       maxRsq(vbf.maxRsq),
0026       maxZ(vbf.maxZ),
0027       paramField(vbf.paramField),
0028       magGeomOwned(false),
0029       paramFieldOwned(false) {
0030   // std::cout << "VolumeBasedMagneticField::clone() (shallow copy)" << std::endl;
0031   setNominalValue();
0032 }
0033 
0034 MagneticField* VolumeBasedMagneticField::clone() const { return new VolumeBasedMagneticField(*this); }
0035 
0036 VolumeBasedMagneticField::~VolumeBasedMagneticField() {
0037   if (magGeomOwned)
0038     delete field;
0039   if (paramFieldOwned)
0040     delete paramField;
0041 }
0042 
0043 GlobalVector VolumeBasedMagneticField::inTesla(const GlobalPoint& gp) const {
0044   // If parametrization of the inner region is available, use it.
0045   if (paramField && paramField->isDefined(gp))
0046     return paramField->inTeslaUnchecked(gp);
0047 
0048   // If point is outside magfield map, return 0 field (not an error)
0049   if (!isDefined(gp))
0050     return GlobalVector();
0051 
0052   return field->fieldInTesla(gp);
0053 }
0054 
0055 GlobalVector VolumeBasedMagneticField::inTeslaUnchecked(const GlobalPoint& gp) const {
0056   //same as above, but do not check range
0057   if (paramField && paramField->isDefined(gp))
0058     return paramField->inTeslaUnchecked(gp);
0059   return field->fieldInTesla(gp);
0060 }
0061 
0062 const MagVolume* VolumeBasedMagneticField::findVolume(const GlobalPoint& gp) const { return field->findVolume(gp); }
0063 
0064 bool VolumeBasedMagneticField::isDefined(const GlobalPoint& gp) const {
0065   return (fabs(gp.z()) < maxZ && gp.perp2() < maxRsq);
0066 }