/** * Get the sample component. Use the name provided as a property as the basis *for the lookup as a priority. * * Throws if the name is invalid. * @param inst : Instrument to search through * @return : The component : The component object found. */ Mantid::Geometry::IComponent_const_sptr SpecularReflectionAlgorithm::getSurfaceSampleComponent( Mantid::Geometry::Instrument_const_sptr inst) const { std::string sampleComponent = "some-surface-holder"; if (!isPropertyDefault("SampleComponentName")) { sampleComponent = this->getPropertyValue("SampleComponentName"); } auto searchResult = inst->getComponentByName(sampleComponent); if (searchResult == nullptr) { throw std::invalid_argument(sampleComponent + " does not exist. Check input properties."); } return searchResult; }
/** * Get the detector component. Use the name provided as a property as the basis *for the lookup as a priority. * * Throws if the name is invalid. * @param workspace : Workspace from instrument with detectors * @param isPointDetector : True if this is a point detector. Used to guess a *name. * @return The component : The component object found. */ boost::shared_ptr<const Mantid::Geometry::IComponent> SpecularReflectionAlgorithm::getDetectorComponent( MatrixWorkspace_sptr workspace, const bool isPointDetector) const { boost::shared_ptr<const IComponent> searchResult; if (!isPropertyDefault("SpectrumNumbersOfDetectors")) { const std::vector<int> spectrumNumbers = this->getProperty("SpectrumNumbersOfDetectors"); const bool strictSpectrumChecking = this->getProperty("StrictSpectrumChecking"); checkSpectrumNumbers(spectrumNumbers, strictSpectrumChecking, g_log); auto specToWorkspaceIndex = workspace->getSpectrumToWorkspaceIndexMap(); DetectorGroup_sptr allDetectors = boost::make_shared<DetectorGroup>(); const auto &spectrumInfo = workspace->spectrumInfo(); for (auto index : spectrumNumbers) { const size_t spectrumNumber{static_cast<size_t>(index)}; auto it = specToWorkspaceIndex.find(index); if (it == specToWorkspaceIndex.end()) { std::stringstream message; message << "Spectrum number " << spectrumNumber << " does not exist in the InputWorkspace"; throw std::invalid_argument(message.str()); } const size_t workspaceIndex = it->second; auto detector = workspace->getDetector(workspaceIndex); if (spectrumInfo.isMasked(workspaceIndex)) g_log.warning() << "Adding a detector (ID:" << detector->getID() << ") that is flagged as masked.\n"; allDetectors->addDetector(detector); } searchResult = allDetectors; } else { Mantid::Geometry::Instrument_const_sptr inst = workspace->getInstrument(); std::string componentToCorrect = isPointDetector ? "point-detector" : "linedetector"; if (!isPropertyDefault("DetectorComponentName")) { componentToCorrect = this->getPropertyValue("DetectorComponentName"); } searchResult = inst->getComponentByName(componentToCorrect); if (searchResult == nullptr) { throw std::invalid_argument(componentToCorrect + " does not exist. Check input properties."); } } return searchResult; }
/** * Gets the eFixed value from the workspace using the instrument parameters. * * @param ws Pointer to the workspace * @return eFixed value */ double IndirectTab::getEFixed(Mantid::API::MatrixWorkspace_sptr ws) { Mantid::Geometry::Instrument_const_sptr inst = ws->getInstrument(); if (!inst) throw std::runtime_error("No instrument on workspace"); // Try to get the parameter form the base instrument if (inst->hasParameter("Efixed")) return inst->getNumberParameter("Efixed")[0]; // Try to get it form the analyser component if (inst->hasParameter("analyser")) { std::string analyserName = inst->getStringParameter("analyser")[0]; auto analyserComp = inst->getComponentByName(analyserName); if (analyserComp && analyserComp->hasParameter("Efixed")) return analyserComp->getNumberParameter("Efixed")[0]; } throw std::runtime_error("Instrument has no efixed parameter"); }
/** @param inst Instrument @param bankName Name of detector bank @param col Column number containing peak @param row Row number containing peak @param Edge Number of edge points for each bank @return True if peak is on edge */ bool edgePixel(Mantid::Geometry::Instrument_const_sptr inst, std::string bankName, int col, int row, int Edge) { if (bankName == "None") return false; boost::shared_ptr<const Geometry::IComponent> parent = inst->getComponentByName(bankName); if (parent->type() == "RectangularDetector") { boost::shared_ptr<const Geometry::RectangularDetector> RDet = boost::dynamic_pointer_cast<const Geometry::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); int startI = 1; if (children[0]->getName() == "sixteenpack") { startI = 0; parent = children[0]; children.clear(); 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 - startI < Edge || col - startI >= (NCOLS - Edge) || row - startI < Edge || row - startI >= (NROWS - Edge); } return false; }