/** Execute the algorithm. */ void SaveIsawUB::exec() { try { Workspace_sptr ws1 = getProperty("InputWorkspace"); ExperimentInfo_sptr ws; MultipleExperimentInfos_sptr MDWS = boost::dynamic_pointer_cast<MultipleExperimentInfos>(ws1); if (MDWS != nullptr) { ws = MDWS->getExperimentInfo(0); } else { ws = boost::dynamic_pointer_cast<ExperimentInfo>(ws1); } if (!ws) throw std::invalid_argument("Must specify either a MatrixWorkspace or a " "PeaksWorkspace or a MDWorkspace."); if (!ws->sample().hasOrientedLattice()) throw std::invalid_argument( "Workspace must have an oriented lattice to save"); std::string Filename = getProperty("Filename"); ofstream out; out.open(Filename.c_str()); OrientedLattice lattice = ws->sample().getOrientedLattice(); Kernel::DblMatrix ub = lattice.getUB(); Kernel::DblMatrix modub = lattice.getModUB(); // Write the ISAW UB matrix const int beam = 2; const int up = 1; const int back = 0; out << fixed; for (size_t basis = 0; basis < 3; basis++) { out << setw(11) << setprecision(8) << ub[beam][basis] << setw(12) << setprecision(8) << ub[back][basis] << setw(12) << setprecision(8) << ub[up][basis] << " \n"; } int ModDim = 0; for (int i = 0; i < 3; i++) { if (lattice.getModVec(i) == V3D(0, 0, 0)) continue; else ModDim++; } if (ModDim > 0) { out << "ModUB: \n"; for (size_t basis = 0; basis < 3; basis++) { out << setw(11) << setprecision(8) << modub[beam][basis] << setw(12) << setprecision(8) << modub[back][basis] << setw(12) << setprecision(8) << modub[up][basis] << " \n"; } } // out << "Lattice Parameters: \n"; out << setw(11) << setprecision(4) << lattice.a() << setw(12) << setprecision(4) << lattice.b() << setw(12) << setprecision(4) << lattice.c() << setw(12) << setprecision(4) << lattice.alpha() << setw(12) << setprecision(4) << lattice.beta() << setw(12) << setprecision(4) << lattice.gamma() << setw(12) << setprecision(4) << lattice.volume() << " \n"; double ErrorVolume = getErrorVolume(lattice); out << setw(11) << setprecision(4) << lattice.errora() << setw(12) << setprecision(4) << lattice.errorb() << setw(12) << setprecision(4) << lattice.errorc() << setw(12) << setprecision(4) << lattice.erroralpha() << setw(12) << setprecision(4) << lattice.errorbeta() << setw(12) << setprecision(4) << lattice.errorgamma() << setw(12) << setprecision(4) << ErrorVolume << " \n"; out << "\n"; if (ModDim >= 1) { out << "Modulation Vector 1: " << setw(12) << setprecision(4) << lattice.getdh(0) << setw(12) << setprecision(4) << lattice.getdk(0) << setw(12) << setprecision(4) << lattice.getdl(0) << " \n"; out << "Modulation Vector 1 error: " << setw(6) << setprecision(4) << lattice.getdherr(0) << setw(12) << setprecision(4) << lattice.getdkerr(0) << setw(12) << setprecision(4) << lattice.getdlerr(0) << " \n\n"; } if (ModDim >= 2) { out << "Modulation Vector 2: " << setw(12) << setprecision(4) << lattice.getdh(1) << setw(12) << setprecision(4) << lattice.getdk(1) << setw(12) << setprecision(4) << lattice.getdl(1) << " \n"; out << "Modulation Vector 2 error: " << setw(6) << setprecision(4) << lattice.getdherr(1) << setw(12) << setprecision(4) << lattice.getdkerr(1) << setw(12) << setprecision(4) << lattice.getdlerr(1) << " \n\n"; } if (ModDim == 3) { out << "Modulation Vector 3: " << setw(12) << setprecision(4) << lattice.getdh(2) << setw(12) << setprecision(4) << lattice.getdk(2) << setw(12) << setprecision(4) << lattice.getdl(2) << " \n"; out << "Modulation Vector 3 error: " << setw(6) << setprecision(4) << lattice.getdherr(2) << setw(12) << setprecision(4) << lattice.getdkerr(2) << setw(12) << setprecision(4) << lattice.getdlerr(2) << " \n\n"; } if (ModDim >= 1) { out << "Max Order: " << lattice.getMaxOrder() << " \n"; out << "Cross Terms: " << lattice.getCrossTerm() << " \n"; } out << "\n"; if (ModDim == 0) { out << "The above matrix is the Transpose of the UB Matrix. "; out << "The UB matrix maps the column\n"; out << "vector (h,k,l ) to the column vector "; out << "(q'x,q'y,q'z).\n"; out << "|Q'|=1/dspacing and its coordinates are a "; out << "right-hand coordinate system where\n"; out << " x is the beam direction and z is vertically "; out << "upward.(IPNS convention)\n"; } else { out << "The above matrix is the Transpose of the UB Matrix and the " "Transpose of ModUB. "; out << "The UB matrix together with ModUB maps the column vector " "(h,k,l,m,n,p) \n"; out << "to the column vector (q'x,q'y,q'z).\n"; out << "The columns of ModUB are the coordinates of modulation vectors " "in Qlab. \n"; out << "|Q'|=1/dspacing and its coordinates are a "; out << "right-hand coordinate system where"; out << " x is the beam direction and z is vertically "; out << "upward.(IPNS convention)\n"; } out.close(); } catch (exception &s) { throw std::invalid_argument(s.what()); } }
/** Execute the algorithm. */ void SaveIsawUB::exec() { try { Workspace_sptr ws1 = getProperty("InputWorkspace"); ExperimentInfo_sptr ws = boost::dynamic_pointer_cast<ExperimentInfo>(ws1); if (!ws) throw std::invalid_argument( "Must specify either a MatrixWorkspace or a PeaksWorkspace or a MDEventWorkspace."); if (!ws->sample().hasOrientedLattice()) throw std::invalid_argument("Workspace must have an oriented lattice to save"); std::string Filename = getProperty("Filename"); ofstream out; out.open(Filename.c_str()); OrientedLattice lattice = ws->sample().getOrientedLattice(); Kernel::DblMatrix ub = lattice.getUB(); // Write the ISAW UB matrix const int beam = 2; const int up = 1; const int back = 0; out << fixed; for (size_t basis = 0; basis < 3; basis++) { out << setw(11) << setprecision(8) << ub[beam][basis] << setw(12) << setprecision(8) << ub[back][basis] << setw(12) << setprecision(8) << ub[up][basis] << " " << endl; } out << setw(11) << setprecision(4) << lattice.a() << setw(12) << setprecision(4) << lattice.b() << setw(12) << setprecision(4) << lattice.c() << setw(12) << setprecision(4) << lattice.alpha() << setw(12) << setprecision(4) << lattice.beta() << setw(12) << setprecision(4) << lattice.gamma() << setw(12) << setprecision(4) << lattice.volume() << " " << endl; out << " 0.0000" << " 0.0000" << " 0.0000" << " 0.0000" << " 0.0000" << " 0.0000" << " 0.0000 " << endl; out << endl << endl; out << "The above matrix is the Transpose of the UB Matrix. "; out << "The UB matrix maps the column" << endl; out << "vector (h,k,l ) to the column vector "; out << "(q'x,q'y,q'z)." << endl; out << "|Q'|=1/dspacing and its coordinates are a "; out << "right-hand coordinate system where" << endl; out << " x is the beam direction and z is vertically "; out << "upward.(IPNS convention)" << endl; out.close(); } catch (exception &s) { throw std::invalid_argument(s.what()); } }