本文整理汇总了C++中geometry::Instrument_const_sptr类的典型用法代码示例。如果您正苦于以下问题:C++ Instrument_const_sptr类的具体用法?C++ Instrument_const_sptr怎么用?C++ Instrument_const_sptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Instrument_const_sptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findPixelID
int MaskPeaksWorkspace::findPixelID(std::string bankName, int col, int row) {
Geometry::Instrument_const_sptr Iptr = m_inputW->getInstrument();
boost::shared_ptr<const IComponent> parent =
Iptr->getComponentByName(bankName);
if (parent->type().compare("RectangularDetector") == 0) {
boost::shared_ptr<const RectangularDetector> RDet =
boost::dynamic_pointer_cast<const RectangularDetector>(parent);
boost::shared_ptr<Detector> pixel = RDet->getAtXY(col, row);
return pixel->getID();
} else {
std::string bankName0 = bankName;
// Only works for WISH
bankName0.erase(0, 4);
std::ostringstream pixelString;
pixelString << Iptr->getName() << "/" << bankName0 << "/" << bankName
<< "/tube" << std::setw(3) << std::setfill('0') << col
<< "/pixel" << std::setw(4) << std::setfill('0') << row;
boost::shared_ptr<const Geometry::IComponent> component =
Iptr->getComponentByName(pixelString.str());
boost::shared_ptr<const Detector> pixel =
boost::dynamic_pointer_cast<const Detector>(component);
return pixel->getID();
}
}
示例2: createNewPeak
Peak PeakHKLErrors::createNewPeak(const Geometry::IPeak &peak_old,
Geometry::Instrument_sptr instrNew, double T0,
double L0) {
Geometry::Instrument_const_sptr inst = peak_old.getInstrument();
if (inst->getComponentID() != instrNew->getComponentID()) {
g_log.error("All peaks must have the same instrument");
throw std::invalid_argument("All peaks must have the same instrument");
}
double T = peak_old.getTOF() + T0;
int ID = peak_old.getDetectorID();
Kernel::V3D hkl = peak_old.getHKL();
// peak_old.setDetectorID(ID); //set det positions
Peak peak(instrNew, ID, peak_old.getWavelength(), hkl,
peak_old.getGoniometerMatrix());
Wavelength wl;
wl.initialize(L0, peak.getL2(), peak.getScattering(), 0,
peak_old.getInitialEnergy(), 0.0);
peak.setWavelength(wl.singleFromTOF(T));
peak.setIntensity(peak_old.getIntensity());
peak.setSigmaIntensity(peak_old.getSigmaIntensity());
peak.setRunNumber(peak_old.getRunNumber());
peak.setBinCount(peak_old.getBinCount());
//!!!peak.setDetectorID(ID);
return peak;
}
示例3: adjustInstrument
/**
* Apply any instrument adjustments from the file
* @param filename :: The file to take the positions
*/
void CreateSimulationWorkspace::adjustInstrument(const std::string &filename) {
// If requested update the instrument to positions in the raw file
const Geometry::ParameterMap &pmap = m_outputWS->instrumentParameters();
Geometry::Instrument_const_sptr instrument = m_outputWS->getInstrument();
boost::shared_ptr<Geometry::Parameter> updateDets =
pmap.get(instrument->getComponentID(), "det-pos-source");
if (!updateDets)
return; // No tag, use IDF
std::string value = updateDets->value<std::string>();
if (value.substr(0, 8) == "datafile") {
IAlgorithm_sptr updateInst =
createChildAlgorithm("UpdateInstrumentFromFile", 0.75, 1.0);
updateInst->setProperty<MatrixWorkspace_sptr>("Workspace", m_outputWS);
updateInst->setPropertyValue("Filename", filename);
if (value == "datafile-ignore-phi") {
updateInst->setProperty("IgnorePhi", true);
g_log.information("Detector positions in IDF updated with positions in "
"the data file except for the phi values");
} else {
g_log.information(
"Detector positions in IDF updated with positions in the data file");
}
// We want this to throw if it fails to warn the user that the information
// is not correct.
updateInst->execute();
}
}
示例4: getComponentPosition
/**
* Get position in space of a componentName
*/
V3D LoadILLSANS::getComponentPosition(const std::string &componentName) {
Geometry::Instrument_const_sptr instrument =
m_localWorkspace->getInstrument();
Geometry::IComponent_const_sptr component =
instrument->getComponentByName(componentName);
return component->getPos();
}
示例5: moveComponent
void LoadILLIndirect::moveComponent(const std::string &componentName,
double twoTheta, double offSet) {
try {
Geometry::Instrument_const_sptr instrument =
m_localWorkspace->getInstrument();
Geometry::IComponent_const_sptr component =
instrument->getComponentByName(componentName);
double r, theta, phi, newTheta, newR;
V3D oldPos = component->getPos();
oldPos.getSpherical(r, theta, phi);
newTheta = twoTheta;
newR = offSet;
V3D newPos;
newPos.spherical(newR, newTheta, phi);
// g_log.debug() << tube->getName() << " : t = " << theta << " ==> t = " <<
// newTheta << "\n";
Geometry::ParameterMap &pmap = m_localWorkspace->instrumentParameters();
Geometry::ComponentHelper::moveComponent(
*component, pmap, newPos, Geometry::ComponentHelper::Absolute);
} catch (Mantid::Kernel::Exception::NotFoundError &) {
throw std::runtime_error("Error when trying to move the " + componentName +
" : NotFoundError");
} catch (std::runtime_error &) {
throw std::runtime_error("Error when trying to move the " + componentName +
" : runtime_error");
}
}
示例6: bankToDetectors
/** Convert bank to detectors
* This routine has never been used. Dead code.
* @param singlebanks -- vector of string containing bank names
* @param detectors -- vector of detector-id-s belonging to these banks
*/
void LoadMask::bankToDetectors(const std::vector<std::string> &singlebanks,
std::vector<detid_t> &detectors) {
std::stringstream infoss;
infoss << "Bank IDs to be converted to detectors: \n";
for (auto &singlebank : singlebanks) {
infoss << "Bank: " << singlebank << '\n';
}
g_log.debug(infoss.str());
Geometry::Instrument_const_sptr minstrument = m_maskWS->getInstrument();
for (auto &singlebank : singlebanks) {
std::vector<Geometry::IDetector_const_sptr> idetectors;
minstrument->getDetectorsInBank(idetectors, singlebank);
g_log.debug() << "Bank: " << singlebank << " has " << idetectors.size()
<< " detectors\n";
// a) get information
size_t numdets = idetectors.size();
detid_t detid_first = idetectors.front()->getID();
detid_t detid_last = idetectors.back()->getID();
// b) set detectors
for (const auto &det : idetectors) {
detid_t detid = det->getID();
detectors.push_back(detid);
}
g_log.debug() << "Number of Detectors in Bank " << singlebank
<< " is: " << numdets << "\nRange From: " << detid_first
<< " To: " << detid_last << '\n';
} // ENDFOR
}
示例7: edgePixel
bool CentroidPeaks::edgePixel(std::string bankName, int col, int row,
int Edge) {
if (bankName.compare("None") == 0)
return false;
Geometry::Instrument_const_sptr Iptr = inWS->getInstrument();
boost::shared_ptr<const IComponent> parent =
Iptr->getComponentByName(bankName);
if (parent->type().compare("RectangularDetector") == 0) {
boost::shared_ptr<const RectangularDetector> RDet =
boost::dynamic_pointer_cast<const RectangularDetector>(parent);
return col < Edge || col >= (RDet->xpixels() - Edge) || row < Edge ||
row >= (RDet->ypixels() - Edge);
} else {
std::vector<Geometry::IComponent_const_sptr> children;
boost::shared_ptr<const Geometry::ICompAssembly> asmb =
boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(parent);
asmb->getChildren(children, false);
boost::shared_ptr<const Geometry::ICompAssembly> asmb2 =
boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(children[0]);
std::vector<Geometry::IComponent_const_sptr> grandchildren;
asmb2->getChildren(grandchildren, false);
int NROWS = static_cast<int>(grandchildren.size());
int NCOLS = static_cast<int>(children.size());
// Wish pixels and tubes start at 1 not 0
return col - 1 < Edge || col - 1 >= (NCOLS - Edge) || row - 1 < Edge ||
row - 1 >= (NROWS - Edge);
}
return false;
}
示例8:
double LoadHelper::getL1(const API::MatrixWorkspace_sptr& workspace)
{
Geometry::Instrument_const_sptr instrument = workspace->getInstrument();
Geometry::IComponent_const_sptr sample = instrument->getSample();
double l1 = instrument->getSource()->getDistance(*sample);
return l1;
}
示例9: calculateDetectorPosition
/** Retrieves the detector postion for a given spectrum
* @param index :: The workspace index of the spectrum
* @param l1 :: Returns the source-sample distance
* @param l2 :: Returns the sample-detector distance
* @param twoTheta :: Returns the detector's scattering angle
*/
void RemoveBins::calculateDetectorPosition(const int& index, double& l1, double& l2, double& twoTheta)
{
// Get a pointer to the instrument contained in the workspace
Geometry::Instrument_const_sptr instrument = m_inputWorkspace->getInstrument();
// Get the distance between the source and the sample (assume in metres)
Geometry::IObjComponent_const_sptr sample = instrument->getSample();
// Check for valid instrument
if (sample == NULL)
{
throw Exception::InstrumentDefinitionError("Instrument not sufficiently defined: failed to get sample");
}
l1 = instrument->getSource()->getDistance(*sample);
Geometry::IDetector_const_sptr det = m_inputWorkspace->getDetector(index);
// Get the sample-detector distance for this detector (in metres)
if ( ! det->isMonitor() )
{
l2 = det->getDistance(*sample);
// The scattering angle for this detector (in radians).
twoTheta = m_inputWorkspace->detectorTwoTheta(det);
}
else // If this is a monitor then make l1+l2 = source-detector distance and twoTheta=0
{
l2 = det->getDistance(*(instrument->getSource()));
l2 = l2 - l1;
twoTheta = 0.0;
}
g_log.debug() << "Detector for index " << index << " has L1+L2=" << l1+l2 << " & 2theta= " << twoTheta << std::endl;
return;
}
示例10: makeInstrumentMap
/** This function will check how to group spectra when calculating median
*
*
*/
std::vector<std::vector<size_t> > DetectorDiagnostic::makeMap(API::MatrixWorkspace_sptr countsWS)
{
std::multimap<Mantid::Geometry::ComponentID,size_t> mymap;
Geometry::Instrument_const_sptr instrument = countsWS->getInstrument();
if (m_parents==0)
{
return makeInstrumentMap(countsWS);
}
if (!instrument)
{
g_log.warning("Workspace has no instrument. LevelsUP is ignored");
return makeInstrumentMap(countsWS);
}
//check if not grouped. If grouped, it will throw
if ( countsWS->hasGroupedDetectors() )
{
throw std::runtime_error("Median detector test: not able to create detector to spectra map. Try with LevelUp=0.");
}
for(size_t i=0;i < countsWS->getNumberHistograms();i++)
{
detid_t d=(*((countsWS->getSpectrum(i))->getDetectorIDs().begin()));
std::vector<boost::shared_ptr<const Mantid::Geometry::IComponent> > anc=instrument->getDetector(d)->getAncestors();
//std::vector<boost::shared_ptr<const IComponent> > anc=(*(countsWS->getSpectrum(i)->getDetectorIDs().begin()))->getAncestors();
if (anc.size()<static_cast<size_t>(m_parents))
{
g_log.warning("Too many levels up. Will ignore LevelsUp");
m_parents=0;
return makeInstrumentMap(countsWS);
}
mymap.insert(std::pair<Mantid::Geometry::ComponentID,size_t>(anc[m_parents-1]->getComponentID(),i));
}
std::vector<std::vector<size_t> > speclist;
std::vector<size_t> speclistsingle;
std::multimap<Mantid::Geometry::ComponentID,size_t>::iterator m_it, s_it;
for (m_it = mymap.begin(); m_it != mymap.end(); m_it = s_it)
{
Mantid::Geometry::ComponentID theKey = (*m_it).first;
std::pair<std::multimap<Mantid::Geometry::ComponentID,size_t>::iterator,std::multimap<Mantid::Geometry::ComponentID,size_t>::iterator> keyRange = mymap.equal_range(theKey);
// Iterate over all map elements with key == theKey
speclistsingle.clear();
for (s_it = keyRange.first; s_it != keyRange.second; ++s_it)
{
speclistsingle.push_back( (*s_it).second );
}
speclist.push_back(speclistsingle);
}
return speclist;
}
示例11: monitorIdReader
// read the monitors list from the workspace and try to do it once for any
// particular ws;
bool MonIDPropChanger::monitorIdReader(
API::MatrixWorkspace_const_sptr inputWS) const {
// no workspace
if (!inputWS)
return false;
// no instrument
Geometry::Instrument_const_sptr pInstr = inputWS->getInstrument();
if (!pInstr)
return false;
std::vector<detid_t> mon = pInstr->getMonitors();
if (mon.empty()) {
if (iExistingAllowedValues.empty()) {
return false;
} else {
iExistingAllowedValues.clear();
return true;
}
}
// are these monitors really there?
// got the index of correspondent spectra.
std::vector<size_t> indexList = inputWS->getIndicesFromDetectorIDs(mon);
if (indexList.empty()) {
if (iExistingAllowedValues.empty()) {
return false;
} else {
iExistingAllowedValues.clear();
return true;
}
}
// index list can be less or equal to the mon list size (some monitors do not
// have spectra)
size_t mon_count =
(mon.size() < indexList.size()) ? mon.size() : indexList.size();
std::vector<int> allowed_values(mon_count);
for (size_t i = 0; i < mon_count; i++) {
allowed_values[i] = mon[i];
}
// are known values the same as the values we have just identified?
if (iExistingAllowedValues.size() != mon_count) {
iExistingAllowedValues.clear();
iExistingAllowedValues.assign(allowed_values.begin(), allowed_values.end());
return true;
}
// the monitor list has the same size as before. Is it equivalent to the
// existing one?
bool values_redefined = false;
for (size_t i = 0; i < mon_count; i++) {
if (iExistingAllowedValues[i] != allowed_values[i]) {
values_redefined = true;
iExistingAllowedValues[i] = allowed_values[i];
}
}
return values_redefined;
}
示例12: monitorIdReader
// read the monitors list from the workspace and try to do it once for any
// particular ws;
bool MonIDPropChanger::monitorIdReader(
MatrixWorkspace_const_sptr inputWS) const {
// no workspace
if (!inputWS)
return false;
// no instrument
Geometry::Instrument_const_sptr pInstr = inputWS->getInstrument();
if (!pInstr)
return false;
// are these monitors really there?
std::vector<detid_t> monitorIDList = pInstr->getMonitors();
{
const auto &specInfo = inputWS->spectrumInfo();
std::set<detid_t> idsInWorkspace;
size_t i = 0;
// Loop over spectra, but finish early if we find everything
while (i < specInfo.size() &&
idsInWorkspace.size() < monitorIDList.size()) {
if (specInfo.isMonitor(i))
idsInWorkspace.insert(specInfo.detector(i).getID());
++i;
}
monitorIDList =
std::vector<detid_t>(idsInWorkspace.begin(), idsInWorkspace.end());
}
if (monitorIDList.empty()) {
if (iExistingAllowedValues.empty()) {
return false;
} else {
iExistingAllowedValues.clear();
return true;
}
}
// are known values the same as the values we have just identified?
if (iExistingAllowedValues.size() != monitorIDList.size()) {
iExistingAllowedValues.clear();
iExistingAllowedValues.assign(monitorIDList.begin(), monitorIDList.end());
return true;
}
// the monitor list has the same size as before. Is it equivalent to the
// existing one?
bool values_redefined = false;
for (size_t i = 0; i < monitorIDList.size(); i++) {
if (iExistingAllowedValues[i] != monitorIDList[i]) {
values_redefined = true;
iExistingAllowedValues[i] = monitorIDList[i];
}
}
return values_redefined;
}
示例13: setupDetectorCache
/**
* Setup a detector cache for randomly picking IDs from the first
* instrument in the ExperimentInfo list.
* @param ws :: The input workspace
*/
void FakeMDEventData::setupDetectorCache(const API::IMDEventWorkspace &ws) {
try {
Geometry::Instrument_const_sptr inst =
ws.getExperimentInfo(0)->getInstrument();
m_detIDs = inst->getDetectorIDs(true); // true=skip monitors
size_t max = m_detIDs.size() - 1;
m_uniformDist = boost::uniform_int<size_t>(0, max); // Includes max
} catch (std::invalid_argument &) {
g_log.information("Cannot retrieve instrument from input workspace, "
"detector information will be garbage.");
}
}
示例14: getComponentPosition
V3D LoadHelper::getComponentPosition(API::MatrixWorkspace_sptr ws, const std::string &componentName)
{
try
{
Geometry::Instrument_const_sptr instrument = ws->getInstrument();
Geometry::IComponent_const_sptr component = instrument->getComponentByName(componentName);
V3D pos = component->getPos();
return pos;
} catch (Mantid::Kernel::Exception::NotFoundError&)
{
throw std::runtime_error("Error when trying to move the " + componentName + " : NotFoundError");
}
}
示例15: componentToDetectors
/** Extract a component's detectors and return it within detectors array
* It is a generalized version of bankToDetectors()
*
* @param componentnames -- vector of component names to process
* @param detectors -- vector of detector ids, which belongs to components
*provided as input.
*/
void LoadMask::componentToDetectors(
const std::vector<std::string> &componentnames,
std::vector<detid_t> &detectors) {
Geometry::Instrument_const_sptr minstrument = m_maskWS->getInstrument();
for (auto &componentname : componentnames) {
g_log.debug() << "Component name = " << componentname << '\n';
// a) get component
Geometry::IComponent_const_sptr component =
minstrument->getComponentByName(componentname);
if (component)
g_log.debug() << "Component ID = " << component->getComponentID() << '\n';
else {
// A non-exiting component. Ignore
g_log.warning() << "Component " << componentname << " does not exist!\n";
continue;
}
// b) component -> component assembly --> children (more than detectors)
boost::shared_ptr<const Geometry::ICompAssembly> asmb =
boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(component);
std::vector<Geometry::IComponent_const_sptr> children;
asmb->getChildren(children, true);
g_log.debug() << "Number of Children = " << children.size() << '\n';
size_t numdets(0);
detid_t id_min(std::numeric_limits<Mantid::detid_t>::max());
detid_t id_max(0);
for (const auto &child : children) {
// c) convert component to detector
Geometry::IDetector_const_sptr det =
boost::dynamic_pointer_cast<const Geometry::IDetector>(child);
if (det) {
detid_t detid = det->getID();
detectors.push_back(detid);
numdets++;
if (detid < id_min)
id_min = detid;
if (detid > id_max)
id_max = detid;
}
}
g_log.debug() << "Number of Detectors in Children = " << numdets
<< " Range = " << id_min << ", " << id_max << '\n';
} // for component
}