Skip to content

Commit

Permalink
Refs #6940 merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Vickie Lynch committed Jun 4, 2013
2 parents db7c13f + 523917c commit 58ff25f
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 7 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/IPeaksWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ namespace API
* @returns special Q3D coordinate system to use being used by this PeaksWorkspace object. Probably the one the workspace was generated with.
*/
virtual Mantid::API::SpecialCoordinateSystem getSpecialCoordinateSystem() const = 0;
virtual int PeakInfoNumber(Kernel::V3D QLabFrame , bool lab_coords) const =0;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ namespace DataObjects
const Peak & getPeak(int peakNum) const;
API::IPeak* createPeak(Kernel::V3D QLabFrame, double detectorDistance=1.0) const;
std::vector<std::pair<std::string,std::string> > PeakInfo(Kernel::V3D QFrame , bool lab_coords) const;
int PeakInfoNumber(Kernel::V3D QFrame, bool lab_coords) const;
std::vector<Peak> & getPeaks();
const std::vector<Peak> & getPeaks() const;
virtual bool hasIntegratedPeaks() const;
Expand Down
46 changes: 46 additions & 0 deletions Code/Mantid/Framework/DataObjects/src/PeaksWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,52 @@ namespace Mantid
return Result;
}

/**
* Returns selected information for a "peak" at QLabFrame.
*
* @param QFrame An arbitrary position in Q-space. This does not have to be the
* position of a peak.
* @param lab_coords Set true if the position is in the lab coordinate system, false if
* it is in the sample coordinate system.
* @return a vector whose elements contain different information about the "peak" at that position.
* each element is a pair of description of information and the string form for the corresponding
* value.
*/
int PeaksWorkspace::PeakInfoNumber(Kernel::V3D QFrame,
bool lab_coords) const
{
std::vector<std::pair<std::string, std::string> > Result;
std::ostringstream oss;
oss<<std::setw(12)<<std::fixed<<std::setprecision(3)<<(QFrame.norm());
std::pair<std::string, std::string> QMag("|Q|",oss.str());
Result.push_back(QMag);

oss.str(""); oss.clear();
oss<<std::setw(12)<<std::fixed<<std::setprecision(3)<<(2.0 * M_PI / QFrame.norm());

std::pair<std::string, std::string> dspc("d-spacing",oss.str());
oss.str(""); oss.clear();
Result.push_back(dspc);

int seqNum = -1;
double minDist = 10000000;

for (int i = 0; i < getNumberPeaks(); i++)
{
Peak pk = getPeak(i);
V3D Q = pk.getQLabFrame();
if (!lab_coords)
Q = pk.getQSampleFrame();
double D = QFrame.distance(Q);
if (D < minDist)
{
minDist = D;
seqNum = i + 1;
}

}
return seqNum;
}

//---------------------------------------------------------------------------------------------
/** Return a reference to the Peaks vector */
Expand Down
31 changes: 24 additions & 7 deletions Code/Mantid/Framework/MDEvents/src/SaveIsawQvector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,15 @@ namespace MDEvents
std::vector<std::string> exts;
exts.push_back(".bin");

declareProperty(new FileProperty("Filename", "", FileProperty::Save, exts),
"Path to an hkl file to save.");
declareProperty(new FileProperty("Filename", "", FileProperty::OptionalSave, exts),
"Optional path to an hkl file to save.");
declareProperty("RightHanded", true, "Save the Q-vector as k_f - k_i");
declareProperty("ISAWcoords", true, "Save the Q-vector with y gravitationally up and x pointing downstream");
std::vector<double>Qx_save,Qy_save,Qz_save;
declareProperty("Qx_vector", Qx_save, "The name of the vector in which to store the list of Qx", Direction::Output);
declareProperty("Qy_vector", Qy_save, "The name of the vector in which to store the list of Qy", Direction::Output);
declareProperty("Qz_vector", Qz_save, "The name of the vector in which to store the list of Qz", Direction::Output);

}

//----------------------------------------------------------------------------------------------
Expand All @@ -111,9 +116,13 @@ namespace MDEvents

// open the output file
std::string filename = getPropertyValue("Filename");
std::ofstream handle(filename.c_str(), std::ios::out | std::ios::binary);
if (!handle.is_open())
throw std::runtime_error("Failed to open file for writing");
std::ofstream handle;
if (!filename.empty())
{
handle.open(filename.c_str(), std::ios::out | std::ios::binary);
if (!handle.is_open())
throw std::runtime_error("Failed to open file for writing");
}
// set up a descripter of where we are going
this->initTargetWSDescr(wksp);

Expand Down Expand Up @@ -150,6 +159,7 @@ namespace MDEvents

// loop through the eventlists
float buffer[DIMS];
std::vector<double>Qx_save,Qy_save,Qz_save;
for (std::size_t i = 0; i < numSpectra; ++i)
{
// get a reference to the event list
Expand Down Expand Up @@ -179,14 +189,21 @@ namespace MDEvents
{
buffer[dim] = static_cast<float>(coord_signs[dim] * locCoord[coord_map[dim]]);
}
handle.write(reinterpret_cast<char*>(buffer), BUFF_SIZE);
Qx_save.push_back(static_cast<double>(buffer[0]));
Qy_save.push_back(static_cast<double>(buffer[1]));
Qz_save.push_back(static_cast<double>(buffer[2]));
if (!filename.empty()) handle.write(reinterpret_cast<char*>(buffer), BUFF_SIZE);
} // end of loop over events in list

prog.report();
} // end of loop over spectra
setProperty("Qx_vector", Qx_save);
setProperty("Qy_vector", Qy_save);
setProperty("Qz_vector", Qz_save);


// cleanup
handle.close();
if (!filename.empty())handle.close();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void export_IPeaksWorkspace()
.def("hasIntegratedPeaks", &IPeaksWorkspace::hasIntegratedPeaks, "Determine if the peaks have been integrated")
.def("getRun", &IPeaksWorkspace::mutableRun, return_internal_reference<>(),
"Return the Run object for this workspace")
.def("PeakInfoNumber", &IPeaksWorkspace::PeakInfoNumber, "Peak info number at Q vector for this workspace")
;

REGISTER_SINGLEVALUE_HANDLER(IPeaksWorkspace_sptr);
Expand Down

0 comments on commit 58ff25f

Please sign in to comment.