// AK20110616 Class to implement a 3D field map // Modified from BLCMDfieldmap.cc from G4beamline v2.03 // // #include #include "IFieldMap.hxx" #include "IFieldMapDescription.hxx" #include using namespace COMET; IFieldMap::IFieldMap(std::string mapFileName, Double_t scaling, Double_t gradient, Double_t timeOffset, const TVector3* translation, const TRotation* rotation) : IElementField(translation,rotation), fFilename(mapFileName) , fScaling(scaling), fGradient(gradient), fTimeOffset(timeOffset){ fMap = new IBLFieldMap(); fIsGood = fMap->readFile(mapFileName); if(fIsGood){ //Set fBoundingBox to be the extent of the field map fMap->getBoundingBox(fBoundingBox); } } IFieldMap::~IFieldMap() { delete fMap; } void IFieldMap::getFieldValue(const Double_t LocalPoint[4], Double_t LocalField[6]) const { fMap->getFieldValue(LocalPoint,LocalField,fScaling,fGradient); } const IElementFieldDescription* IFieldMap::MakeDescription(){ return new IFieldMapDescription( fFilename,fScaling,fGradient,fTimeOffset, GetTranslation(),GetRotation() ); } IFieldMap* IFieldMap::Recreate(const IElementFieldDescription& base){ const IFieldMapDescription& description=*static_cast(&base); std::string filename=description.FindFullFilename(); if (filename.empty()) return NULL; const TVector3* pos = description.Translation(); const TRotation* rot = description.Rotation(); return new COMET::IFieldMap(filename, description.Scaling(), description.Gradient() , description.TimeOffset(), pos, rot); }