예제 #1
0
/**
* This method will, using the NearestNeighbours methods, expand our view on the nearby detectors from
* the standard eight closest that are recorded in the graph.
* @param nearest :: neighbours found in previous requests
* @param spec :: pointer to the central detector, for calculating distances
* @param noNeighbours :: number of neighbours that must be found (in total, including those already found)
* @param bbox :: BoundingBox object representing the search region
* @return true if neighbours were found matching the parameters, false otherwise
*/
bool SpatialGrouping::expandNet(std::map<specid_t,Mantid::Kernel::V3D> & nearest, specid_t spec,
    const size_t & noNeighbours, const Mantid::Geometry::BoundingBox & bbox)
{
  const size_t incoming = nearest.size();

  Mantid::Geometry::IDetector_const_sptr det = m_detectors[spec];

  std::map<specid_t, Mantid::Kernel::V3D> potentials;

  // Special case for first run for this detector
  if ( incoming == 0 )
  {
    potentials = inputWorkspace->getNeighbours(det.get());
  }
  else
  {
    for ( std::map<specid_t,Mantid::Kernel::V3D>::iterator nrsIt = nearest.begin(); nrsIt != nearest.end(); ++nrsIt )
    {
      std::map<specid_t, Mantid::Kernel::V3D> results;
      results = inputWorkspace->getNeighbours(m_detectors[nrsIt->first].get());
      for ( std::map<specid_t, Mantid::Kernel::V3D>::iterator resIt = results.begin(); resIt != results.end(); ++resIt )
      {
        potentials[resIt->first] = resIt->second;
      }
    }
  }

  for ( std::map<specid_t,Mantid::Kernel::V3D>::iterator potIt = potentials.begin(); potIt != potentials.end(); ++potIt )
  {
    // We do not want to include the detector in it's own list of nearest neighbours
    if ( potIt->first == spec ) { continue; }

    // Or detectors that are already in the nearest list passed into this function
    std::map<detid_t, Mantid::Kernel::V3D>::iterator nrsIt = nearest.find(potIt->first);
    if ( nrsIt != nearest.end() ) { continue; }

    // We should not include detectors already included in a group (or monitors for that matter)
    std::set<specid_t>::iterator inclIt = m_included.find(potIt->first);
    if ( inclIt != m_included.end() ) { continue; }

    // If we get this far, we need to determine if the detector is of a suitable distance
    Mantid::Kernel::V3D pos = m_detectors[potIt->first]->getPos();
    if ( ! bbox.isPointInside(pos) ) { continue; }
    
    // Elsewise, it's all good.
    nearest[potIt->first] = potIt->second;
  }

  if ( nearest.size() == incoming ) { return false; }

  if ( nearest.size() > noNeighbours )
  {
    sortByDistance(nearest, noNeighbours);
  }

  return true;
}
예제 #2
0
/**
 * Getter for the masked state of the workspace.
 * @returns True if the detector/detector-group at the workspace index is
 * masked, or if there is no detector at that index.
*/
bool MatrixWorkspaceMDIterator::getIsMasked() const {
  Mantid::Geometry::IDetector_const_sptr det =
      m_ws->getDetector(m_workspaceIndex);
  if (det != nullptr) {
    return det->isMasked();
  } else {
    return true; // TODO. Check whether it's better to return true or false
                 // under these circumstances.
  }
}
예제 #3
0
void InstrumentWindowPickTab::updateSelectionInfo(int detid)
{
  if (m_instrWindow->blocked()) 
  {
    m_selectionInfoDisplay->clear();
    return;
  }
  if (detid >= 0)
  {
    InstrumentActor* instrActor = m_instrWindow->getInstrumentActor();
    Mantid::Geometry::IDetector_const_sptr det = instrActor->getInstrument()->getDetector(detid);
    QString text = "Selected detector: " + QString::fromStdString(det->getName()) + "\n";
    text += "Detector ID: " + QString::number(detid) + '\n';
    QString wsIndex;
    try {
      wsIndex = QString::number(instrActor->getWorkspaceIndex(detid));
      updatePlot(detid); // Update the plot if the detector links to some data
    } catch (Mantid::Kernel::Exception::NotFoundError) {
      // Detector doesn't have a workspace index relating to it
      wsIndex = "None";
      m_plot->clearCurve(); // Clear the plot window
      m_plot->replot();
    }
    text += "Workspace index: " + wsIndex + '\n';
    Mantid::Kernel::V3D pos = det->getPos();
    text += "xyz: " + QString::number(pos.X()) + "," + QString::number(pos.Y()) + "," + QString::number(pos.Z())  + '\n';
    double r,t,p;
    pos.getSpherical(r,t,p);
    text += "rtp: " + QString::number(r) + "," + QString::number(t) + "," + QString::number(p)  + '\n';
    Mantid::Geometry::ICompAssembly_const_sptr parent = boost::dynamic_pointer_cast<const Mantid::Geometry::ICompAssembly>(det->getParent());
    if (parent)
    {
      QString textpath;
      while (parent)
      {
        textpath="/"+QString::fromStdString(parent->getName())+textpath;
        parent=boost::dynamic_pointer_cast<const Mantid::Geometry::ICompAssembly>(parent->getParent());
      }
      text += "Component path:" +textpath+"/"+ QString::fromStdString(det->getName()) +'\n';
    }
    const double integrated = instrActor->getIntegratedCounts(detid);
    const QString counts = integrated == -1.0 ? "N/A" : QString::number(integrated);
    text += "Counts: " + counts + '\n';
    m_selectionInfoDisplay->setText(text);
  }
  else
  {
    m_selectionInfoDisplay->clear();
    m_plot->clearCurve(); // Clear the plot window
    m_plot->replot();
  }
}
예제 #4
0
/*
 * Define edges for each instrument by masking. For CORELLI, tubes 1 and 16, and
 *pixels 0 and 255.
 * Get Q in the lab frame for every peak, call it C
 * For every point on the edge, the trajectory in reciprocal space is a straight
 *line, going through O=V3D(0,0,0).
 * Calculate a point at a fixed momentum, say k=1. Q in the lab frame
 *E=V3D(-k*sin(tt)*cos(ph),-k*sin(tt)*sin(ph),k-k*cos(ph)).
 * Normalize E to 1: E=E*(1./E.norm())
 *
 * @param inst: instrument
 */
void IntegrateEllipsoids::calculateE1(Geometry::Instrument_const_sptr inst) {
  std::vector<detid_t> detectorIDs = inst->getDetectorIDs();

  for (auto &detectorID : detectorIDs) {
    Mantid::Geometry::IDetector_const_sptr det = inst->getDetector(detectorID);
    if (det->isMonitor())
      continue; // skip monitor
    if (!det->isMasked())
      continue; // edge is masked so don't check if not masked
    double tt1 = det->getTwoTheta(V3D(0, 0, 0), V3D(0, 0, 1)); // two theta
    double ph1 = det->getPhi();                                // phi
    V3D E1 = V3D(-std::sin(tt1) * std::cos(ph1), -std::sin(tt1) * std::sin(ph1),
                 1. - std::cos(tt1)); // end of trajectory
    E1 = E1 * (1. / E1.norm());       // normalize
    E1Vec.push_back(E1);
  }
}
예제 #5
0
/**
 * The main method to calculate the ring profile for workspaces based on
 *instruments.
 *
 * It will iterate over all the spectrum inside the workspace.
 * For each spectrum, it will use the RingProfile::getBinForPixel method to
 *identify
 * where, in the output_bins, the sum of all the spectrum values should be
 *placed in.
 *
 * @param inputWS: pointer to the input workspace
 * @param output_bins: the reference to the vector to be filled with the
 *integration values
 */
void RingProfile::processInstrumentRingProfile(
    const API::MatrixWorkspace_sptr inputWS, std::vector<double> &output_bins) {

  for (int i = 0; i < static_cast<int>(inputWS->getNumberHistograms()); i++) {
    m_progress->report("Computing ring bins positions for detectors");
    // for the detector based, the positions will be taken from the detector
    // itself.
    try {
      Mantid::Geometry::IDetector_const_sptr det = inputWS->getDetector(i);

      // skip monitors
      if (det->isMonitor()) {
        continue;
      }

      // this part will be executed if the instrument is attached to the
      // workspace

      // get the bin position
      int bin_n = getBinForPixel(det);

      if (bin_n < 0) // -1 is the agreement for an invalid bin, or outside the
                     // ring being integrated
        continue;

      g_log.debug() << "Bin for the index " << i << " = " << bin_n
                    << " Pos = " << det->getPos() << std::endl;

      // get the reference to the spectrum
      auto spectrum_pt = inputWS->getSpectrum(i);
      const MantidVec &refY = spectrum_pt->dataY();
      // accumulate the values of this spectrum inside this bin
      for (size_t sp_ind = 0; sp_ind < inputWS->blocksize(); sp_ind++)
        output_bins[bin_n] += refY[sp_ind];

    } catch (Kernel::Exception::NotFoundError &ex) {
      g_log.information() << "It found that detector for " << i
                          << " is not valid. " << ex.what() << std::endl;
      continue;
    }
  }
}
예제 #6
0
/** Executes the algorithm
 *
 */
void SumNeighbours::exec()
{
  // Try and retrieve the optional properties
  SumX = getProperty("SumX");
  SumY = getProperty("SumY");


  // Get the input workspace
  Mantid::API::MatrixWorkspace_sptr inWS = getProperty("InputWorkspace");
  Mantid::Geometry::IDetector_const_sptr det = inWS->getDetector(0);
  // Check if grandparent is rectangular detector
  boost::shared_ptr<const Geometry::IComponent> parent = det->getParent()->getParent();
  boost::shared_ptr<const RectangularDetector> rect = boost::dynamic_pointer_cast<const RectangularDetector>(parent);
  
  Mantid::API::MatrixWorkspace_sptr outWS;

  IAlgorithm_sptr smooth = createChildAlgorithm("SmoothNeighbours");
  smooth->setProperty("InputWorkspace", inWS);
  if (rect)
  {
    smooth->setProperty("SumPixelsX",SumX);
    smooth->setProperty("SumPixelsY",SumY);
  }
  else
  {
    smooth->setProperty<std::string>("RadiusUnits","NumberOfPixels");
    smooth->setProperty("Radius",static_cast<double>(SumX*SumY*SumX*SumY));
    smooth->setProperty("NumberOfNeighbours",SumX*SumY*SumX*SumY*4);
    smooth->setProperty("SumNumberOfNeighbours",SumX*SumY);
  }
  smooth->executeAsChildAlg();
  // Get back the result
  outWS = smooth->getProperty("OutputWorkspace");
  //Cast to the matrixOutputWS and save it
  this->setProperty("OutputWorkspace", outWS);

}
예제 #7
0
/**
 * Here is the main logic to perform the transformation, to calculate the bin position in degree for each detector.
 * 
 * The first part of the method is to check if the detector is inside the ring defined as minRadio and maxRadio. 
 * 
 * To do this, it checks the projected distance between the centre and the detector position. If this projected 
 * distance is outside the defined ring, it returns -1. 
 * 
 * For those detectors that lay inside the ring, it will calculate the phi angle. And than find the slot where
 * this angle should be placed (bin)
 * @param det: pointer to the detector from which the positions will be taken
 * @return bin position
 */
int RingProfile::getBinForPixel(Mantid::Geometry::IDetector_const_sptr det ){

    using Mantid::Kernel::V3D; 
    V3D origin(centre_x, centre_y, centre_z); 
    V3D diff_vector = det->getPos()-origin;
    double radio, theta, phi; 
    // get the spherical values of the vector from center to detector position
    diff_vector.getSpherical(radio, theta, phi);

    // the distance from the centre to the ring will be calculated as radio * sin(theta). 
    double effect_distance = radio * sin(theta*M_PI/180);

    //    g_log.debug() << "effect Distance = " << effect_distance << std::endl; 
    
    // check if it is inside the ring defined by min_radius, max_radius
    if ( effect_distance < min_radius || effect_distance > max_radius || effect_distance == 0)
      return -1; 

    // get the angle 
    // g_log.debug() << "The real angle is " << phi << std::endl; 
    return fromAngleToBin(phi); 
}
예제 #8
0
/**
 * Update the info window with information for a selected detector.
 * @param detid :: ID of the selected detector.
 */
void InstrumentWindowPickTab::updateSelectionInfo(int detid)
{
    if (m_freezePlot)
    {   // freeze the plot for one update
        m_freezePlot = false;
        return;
    }
    if (m_instrWindow->blocked())
    {
        m_selectionInfoDisplay->clear();
        return;
    }
    if (detid >= 0)
    {
        InstrumentActor* instrActor = m_instrWindow->getInstrumentActor();
        Mantid::Geometry::IDetector_const_sptr det = instrActor->getInstrument()->getDetector(detid);
        QString text = "Selected detector: " + QString::fromStdString(det->getName()) + "\n";
        text += "Detector ID: " + QString::number(detid) + '\n';
        QString wsIndex;
        try {
            wsIndex = QString::number(instrActor->getWorkspaceIndex(detid));
            updatePlot(detid); // Update the plot if the detector links to some data
        } catch (Mantid::Kernel::Exception::NotFoundError &) {
            // Detector doesn't have a workspace index relating to it
            wsIndex = "None";
            m_plot->clearCurve(); // Clear the plot window
            m_plot->replot();
        }
        text += "Workspace index: " + wsIndex + '\n';
        Mantid::Kernel::V3D pos = det->getPos();
        text += "xyz: " + QString::number(pos.X()) + "," + QString::number(pos.Y()) + "," + QString::number(pos.Z())  + '\n';
        double r,t,p;
        pos.getSpherical(r,t,p);
        text += "rtp: " + QString::number(r) + "," + QString::number(t) + "," + QString::number(p)  + '\n';
        Mantid::Geometry::ICompAssembly_const_sptr parent = boost::dynamic_pointer_cast<const Mantid::Geometry::ICompAssembly>(det->getParent());
        if (parent)
        {
            QString textpath;
            while (parent)
            {
                textpath="/"+QString::fromStdString(parent->getName())+textpath;
                parent=boost::dynamic_pointer_cast<const Mantid::Geometry::ICompAssembly>(parent->getParent());
            }
            text += "Component path:" +textpath+"/"+ QString::fromStdString(det->getName()) +'\n';
        }
        const double integrated = instrActor->getIntegratedCounts(detid);
        const QString counts = integrated == -1.0 ? "N/A" : QString::number(integrated);
        text += "Counts: " + counts + '\n';
        QString xUnits;
        if (m_selectionType > SingleDetectorSelection && !m_plotSum)
        {
            switch(m_tubeXUnits)
            {
            case DETECTOR_ID:
                xUnits = "Detector ID";
                break;
            case LENGTH:
                xUnits = "Length";
                break;
            case PHI:
                xUnits = "Phi";
                break;
            default:
                xUnits = "Detector ID";
            }
        }
        else
        {
            xUnits = QString::fromStdString(instrActor->getWorkspace()->getAxis(0)->unit()->caption());
            //xUnits = "Time of flight";
        }
        text += "X units: " + xUnits + '\n';
        m_selectionInfoDisplay->setText(text);
    }
    else
    {
        m_selectionInfoDisplay->clear();
        m_plot->clearCurve(); // Clear the plot window
        m_plot->replot();
    }
}