コード例 #1
0
ファイル: IO_MuonGrouping.cpp プロジェクト: nimgould/mantid
/**
 * Attempts to load a grouping information referenced by IDF.
 * @param instrument :: Intrument which we went the grouping for
 * @param mainFieldDirection :: (MUSR) orientation of the instrument
 * @return Grouping information
 */
boost::shared_ptr<Grouping> getGroupingFromIDF(Instrument_const_sptr instrument,
                                               const std::string& mainFieldDirection)
{
  std::string parameterName = "Default grouping file";

  // Special case for MUSR, because it has two possible groupings
  if (instrument->getName() == "MUSR")
  {
    parameterName.append(" - " + mainFieldDirection);
  }

  std::vector<std::string> groupingFiles = instrument->getStringParameter(parameterName);

  if ( groupingFiles.size() == 1 )
  {
    const std::string groupingFile = groupingFiles[0];

    // Get search directory for XML instrument definition files (IDFs)
    std::string directoryName = ConfigService::Instance().getInstrumentDirectory();

    auto loadedGrouping = boost::make_shared<Grouping>();
    loadGroupingFromXML(directoryName + groupingFile, *loadedGrouping);

    return loadedGrouping;
  }
  else
  {
    throw std::runtime_error("Multiple groupings specified for the instrument");
  }
}
コード例 #2
0
/**
 * Store required caches
 */
void ModeratorChopperResolution::initCaches() {
    Instrument_const_sptr instr = m_observation.experimentInfo().getInstrument();
    IComponent_const_sptr source = instr->getSource();

    m_modChopDist = m_observation.moderatorToFirstChopperDistance();
    m_chopSampleDist = m_observation.firstChopperToSampleDistance();
}
コード例 #3
0
void CalculateDIFC::calculate() {
  Instrument_const_sptr instrument = m_inputWS->getInstrument();

  SpecialWorkspace2D_sptr localWS =
      boost::dynamic_pointer_cast<SpecialWorkspace2D>(m_outputWS);

  double l1;
  Kernel::V3D beamline, samplePos;
  double beamline_norm;
  instrument->getInstrumentParameters(l1, beamline, beamline_norm, samplePos);

  // To get all the detector ID's
  detid2det_map allDetectors;
  instrument->getDetectors(allDetectors);

  // Now go through all
  detid2det_map::const_iterator it = allDetectors.begin();
  for (; it != allDetectors.end(); ++it) {
    Geometry::IDetector_const_sptr det = it->second;
    if ((!det->isMasked()) && (!det->isMonitor())) {
      const detid_t detID = it->first;
      double offset = 0.;
      if (m_offsetsWS)
        offset = m_offsetsWS->getValue(detID, 0.);

      double difc = Geometry::Instrument::calcConversion(
          l1, beamline, beamline_norm, samplePos, det, offset);
      difc = 1. / difc; // calcConversion gives 1/DIFC
      localWS->setValue(detID, difc);
    }
  }

}
コード例 #4
0
/** Extract mask information from a workspace containing instrument
  * @return vector of detector IDs of detectors that are masked
  */
std::vector<detid_t> ExtractMaskToTable::extractMaskFromMatrixWorkspace() {
  // Clear input
  std::vector<detid_t> maskeddetids;

  // Get on hold of instrument
  Instrument_const_sptr instrument = m_dataWS->getInstrument();
  if (!instrument)
    throw runtime_error("There is no instrument in input workspace.");

  // Extract
  size_t numdets = instrument->getNumberDetectors();
  vector<detid_t> detids = instrument->getDetectorIDs();

  for (size_t i = 0; i < numdets; ++i) {
    detid_t tmpdetid = detids[i];
    IDetector_const_sptr tmpdetector = instrument->getDetector(tmpdetid);
    bool masked = tmpdetector->isMasked();
    if (masked) {
      maskeddetids.push_back(tmpdetid);
    }
    g_log.debug() << "[DB] Detector No. " << i << ":  ID = " << tmpdetid
                  << ", Masked = " << masked << ".\n";
  }

  g_log.notice() << "Extract mask:  There are " << maskeddetids.size()
                 << " detectors that"
                    " are masked."
                 << ".\n";

  return maskeddetids;
}
コード例 #5
0
/** Retrieves the properties and checks that they have valid values.
 *  @throw std::invalid_argument If either workspace has no instrument or the instruments have different base instruments.
 */
void CopyInstrumentParameters::checkProperties()
{

  // Check that both workspaces have an instrument
  Instrument_const_sptr inst = m_givingWorkspace->getInstrument();
  if( !inst )
  {
      throw std::invalid_argument("Input workspace has no instrument");
  }
  Instrument_const_sptr inst2 = m_receivingWorkspace->getInstrument();
  if( !inst2 )
  {
      throw std::invalid_argument("Output workspace has no instrument");
  }

  Instrument_const_sptr baseInstGiv = inst->baseInstrument();
  Instrument_const_sptr baseInstRec = inst2->baseInstrument();

  // Check that both workspaces have the same instrument name
  if( baseInstRec != baseInstGiv )
  {
    m_different_instrument_sp=true;
    g_log.warning() << "The base instrument in the output workspace is not the same as the base instrument in the input workspace."<< std::endl;
  }

}
コード例 #6
0
/**
 * Handles setting default spectra range when an instrument configuration is
 *selected.
 *
 * @param instrumentName Name of selected instrument
 * @param analyserName Name of selected analyser (should always be
 *"diffraction")
 * @param reflectionName Name of diffraction mode selected
 */
void IndirectDiffractionReduction::instrumentSelected(
    const QString &instrumentName, const QString &analyserName,
    const QString &reflectionName) {
  UNUSED_ARG(analyserName);

  // Set the search instrument for runs
  m_uiForm.rfSampleFiles->setInstrumentOverride(instrumentName);
  m_uiForm.rfCanFiles->setInstrumentOverride(instrumentName);

  MatrixWorkspace_sptr instWorkspace = loadInstrument(
      instrumentName.toStdString(), reflectionName.toStdString());
  Instrument_const_sptr instrument = instWorkspace->getInstrument();

  // Get default spectra range
  double specMin = instrument->getNumberParameter("spectra-min")[0];
  double specMax = instrument->getNumberParameter("spectra-max")[0];

  m_uiForm.spSpecMin->setValue(static_cast<int>(specMin));
  m_uiForm.spSpecMax->setValue(static_cast<int>(specMax));

  // Determine whether we need vanadium input
  std::vector<std::string> correctionVector =
      instrument->getStringParameter("Workflow.Diffraction.Correction");
  bool vanadiumNeeded = false;
  if (correctionVector.size() > 0)
    vanadiumNeeded = (correctionVector[0] == "Vanadium");

  if (vanadiumNeeded)
    m_uiForm.swVanadium->setCurrentIndex(0);
  else
    m_uiForm.swVanadium->setCurrentIndex(1);

  // Hide options that the current instrument config cannot process
  if (instrumentName == "OSIRIS" && reflectionName == "diffonly") {
    // Disable individual grouping
    m_uiForm.ckIndividualGrouping->setToolTip(
        "OSIRIS cannot group detectors individually in diffonly mode");
    m_uiForm.ckIndividualGrouping->setEnabled(false);
    m_uiForm.ckIndividualGrouping->setChecked(false);

    // Disable sum files
    m_uiForm.ckSumFiles->setToolTip("OSIRIS cannot sum files in diffonly mode");
    m_uiForm.ckSumFiles->setEnabled(false);
    m_uiForm.ckSumFiles->setChecked(false);

  } else {
    // Re-enable sum files
    m_uiForm.ckSumFiles->setToolTip("");
    m_uiForm.ckSumFiles->setEnabled(true);
    m_uiForm.ckSumFiles->setChecked(true);

    // Re-enable individual grouping
    m_uiForm.ckIndividualGrouping->setToolTip("");
    m_uiForm.ckIndividualGrouping->setEnabled(true);

    // Re-enable spectra range
    m_uiForm.spSpecMin->setEnabled(true);
    m_uiForm.spSpecMax->setEnabled(true);
  }
}
コード例 #7
0
/**
 * Calculate the twoTheta angle from the detector and sample locations.
 * @return: twoTheta
 */
double SpecularReflectionAlgorithm::calculateTwoTheta() const {
  MatrixWorkspace_sptr inWS = this->getProperty("InputWorkspace");

  const std::string analysisMode = this->getProperty("AnalysisMode");

  Instrument_const_sptr instrument = inWS->getInstrument();

  IComponent_const_sptr detector =
      this->getDetectorComponent(inWS, analysisMode == pointDetectorAnalysis);

  IComponent_const_sptr sample = this->getSurfaceSampleComponent(instrument);

  const V3D detSample = detector->getPos() - sample->getPos();

  boost::shared_ptr<const ReferenceFrame> refFrame =
      instrument->getReferenceFrame();

  const double upoffset = refFrame->vecPointingUp().scalar_prod(detSample);
  const double beamoffset =
      refFrame->vecPointingAlongBeam().scalar_prod(detSample);

  const double twoTheta = std::atan2(upoffset, beamoffset) * 180 / M_PI;

  return twoTheta;
}
コード例 #8
0
    /**
     * Updates the analyser and reflection names in the UI when an instrument is selected.
     *
     * @param instrumentName Nmae of instrument
     */
    void IndirectInstrumentConfig::updateInstrumentConfigurations(const QString & instrumentName)
    {
      if(instrumentName.isEmpty())
        return;

      g_log.debug() << "Loading configuration for instrument: " << instrumentName.toStdString() << std::endl;

      bool analyserPreviousBlocking = m_uiForm.cbAnalyser->signalsBlocked();
      m_uiForm.cbAnalyser->blockSignals(true);

      m_uiForm.cbAnalyser->clear();

      IAlgorithm_sptr loadInstAlg = AlgorithmManager::Instance().create("CreateSimulationWorkspace");
      loadInstAlg->initialize();
      loadInstAlg->setChild(true);
      loadInstAlg->setProperty("Instrument", instrumentName.toStdString());
      loadInstAlg->setProperty("BinParams", "0,0.5,1");
      loadInstAlg->setProperty("OutputWorkspace", "__empty_instrument_workspace");
      loadInstAlg->execute();
      MatrixWorkspace_sptr instWorkspace = loadInstAlg->getProperty("OutputWorkspace");

      QList<QPair<QString, QString>> instrumentModes;
      Instrument_const_sptr instrument = instWorkspace->getInstrument();

      std::vector<std::string> ipfAnalysers = instrument->getStringParameter("analysers");
      if(ipfAnalysers.size() == 0)
        return;

      QStringList analysers = QString::fromStdString(ipfAnalysers[0]).split(",");

      for(auto it = analysers.begin(); it != analysers.end(); ++it)
      {
        QString analyser = *it;
        std::string ipfReflections = instrument->getStringParameter("refl-" + analyser.toStdString())[0];
        QStringList reflections = QString::fromStdString(ipfReflections).split(",");

        if(m_removeDiffraction && analyser == "diffraction")
          continue;

        if(m_forceDiffraction && analyser != "diffraction")
          continue;

        if(reflections.size() > 0)
        {
          QVariant data = QVariant(reflections);
          m_uiForm.cbAnalyser->addItem(analyser, data);
        }
        else
        {
          m_uiForm.cbAnalyser->addItem(analyser);
        }
      }

      int index = m_uiForm.cbAnalyser->currentIndex();
      updateReflectionsList(index);

      m_uiForm.cbAnalyser->blockSignals(analyserPreviousBlocking);
    }
コード例 #9
0
/** Get the list of banks, given the settings
 *
 * @return map with key = bank number; value = pointer to the rectangular
 *detector
 */
std::map<int, RectangularDetector_const_sptr>
ConvertToDetectorFaceMD::getBanks() {
  Instrument_const_sptr inst = in_ws->getInstrument();

  std::vector<int> bankNums = this->getProperty("BankNumbers");
  std::sort(bankNums.begin(), bankNums.end());

  std::map<int, RectangularDetector_const_sptr> banks;

  if (bankNums.empty()) {
    // --- Find all rectangular detectors ----
    // Get all children
    std::vector<IComponent_const_sptr> comps;
    inst->getChildren(comps, true);

    for (auto &comp : comps) {
      // Retrieve it
      RectangularDetector_const_sptr det =
          boost::dynamic_pointer_cast<const RectangularDetector>(comp);
      if (det) {
        std::string name = det->getName();
        if (name.size() < 5)
          continue;
        std::string bank = name.substr(4, name.size() - 4);
        int bankNum;
        if (Mantid::Kernel::Strings::convert(bank, bankNum))
          banks[bankNum] = det;
        g_log.debug() << "Found bank " << bank << ".\n";
      }
    }
  } else {
    // -- Find detectors using the numbers given ---
    for (auto &bankNum : bankNums) {
      std::string bankName =
          "bank" + Mantid::Kernel::Strings::toString(bankNum);
      IComponent_const_sptr comp = inst->getComponentByName(bankName);
      RectangularDetector_const_sptr det =
          boost::dynamic_pointer_cast<const RectangularDetector>(comp);
      if (det)
        banks[bankNum] = det;
    }
  }

  for (auto &bank : banks) {
    RectangularDetector_const_sptr det = bank.second;
    // Track the largest detector
    if (det->xpixels() > m_numXPixels)
      m_numXPixels = det->xpixels();
    if (det->ypixels() > m_numYPixels)
      m_numYPixels = det->ypixels();
  }

  if (banks.empty())
    throw std::runtime_error("No RectangularDetectors with a name like "
                             "'bankXX' found in the instrument.");

  return banks;
}
コード例 #10
0
/** Execute the algorithm.
 */
void PolarizationCorrection::exec() {
    WorkspaceGroup_sptr inWS = getProperty("InputWorkspace");
    const std::string analysisMode = getProperty("PolarizationAnalysis");
    const size_t nWorkspaces = inWS->size();

    validateInputWorkspace(inWS);

    Instrument_const_sptr instrument = fetchInstrument(inWS.get());

    // Check if we need to fetch polarization parameters from the instrument's
    // parameters
    std::map<std::string, std::string> loadableProperties;
    loadableProperties[crhoLabel()] = "crho";
    loadableProperties[cppLabel()] = "cPp";

    // In PA mode, we also require cap and calpha
    if (analysisMode == pALabel()) {
        loadableProperties[cApLabel()] = "cAp";
        loadableProperties[cAlphaLabel()] = "calpha";
    }

    for (auto propName = loadableProperties.begin();
            propName != loadableProperties.end(); ++propName) {
        Property *prop = getProperty(propName->first);

        if (!prop)
            continue;

        if (prop->isDefault()) {
            auto vals = instrument->getStringParameter(propName->second);
            if (vals.empty())
                throw std::runtime_error(
                    "Cannot find value for " + propName->first +
                    " in parameter file. Please specify this property manually.");
            prop->setValue(vals[0]);
        }
    }

    WorkspaceGroup_sptr outWS;
    if (analysisMode == pALabel()) {
        if (nWorkspaces != 4) {
            throw std::invalid_argument(
                "For PA analysis, input group must have 4 periods.");
        }
        g_log.notice("PA polarization correction");
        outWS = execPA(inWS);
    } else if (analysisMode == pNRLabel()) {
        if (nWorkspaces != 2) {
            throw std::invalid_argument(
                "For PNR analysis, input group must have 2 periods.");
        }
        outWS = execPNR(inWS);
        g_log.notice("PNR polarization correction");
    }
    this->setProperty("OutputWorkspace", outWS);
}
コード例 #11
0
  /**
   * Make a map of the conversion factors between tof and D-spacing
   * for all pixel IDs in a workspace.
   *
   * @param DFileName name of dspacemap file
   * @param offsetsWS :: OffsetsWorkspace with instrument and offsets
   */
  void SaveDspacemap::CalculateDspaceFromCal(Mantid::DataObjects::OffsetsWorkspace_sptr offsetsWS,
                                    std::string DFileName)
  {
    const char * filename = DFileName.c_str();
    // Get a pointer to the instrument contained in the workspace
    Instrument_const_sptr instrument = offsetsWS->getInstrument();
    double l1;
    Kernel::V3D beamline,samplePos;
    double beamline_norm;
    instrument->getInstrumentParameters(l1,beamline,beamline_norm, samplePos);

    //To get all the detector ID's
    detid2det_map allDetectors;
    instrument->getDetectors(allDetectors);

    detid2det_map::const_iterator it;
    detid_t maxdetID = 0;
    for (it = allDetectors.begin(); it != allDetectors.end(); it++)
    {
      detid_t detectorID = it->first;
      if(detectorID > maxdetID) maxdetID = detectorID;
    }
    detid_t paddetID = detid_t(getProperty("PadDetID"));
    if (maxdetID < paddetID)maxdetID = paddetID;

    // Now write the POWGEN-style Dspace mapping file
    std::ofstream fout(filename, std::ios_base::out|std::ios_base::binary);
    Progress prog(this,0.0,1.0,maxdetID);

    for (detid_t i = 0; i != maxdetID; i++)
    {
      //Compute the factor
      double factor;
      Geometry::IDetector_const_sptr det;
      // Find the detector with that detector id
      it = allDetectors.find(i);
      if (it != allDetectors.end())
      {
        det = it->second;
        factor = Instrument::calcConversion(l1, beamline, beamline_norm, samplePos, det, offsetsWS->getValue(i, 0.0));
        //Factor of 10 between ISAW and Mantid
        factor *= 0.1 ;
        if(factor<0)factor = 0.0;
        fout.write( reinterpret_cast<char*>( &factor ), sizeof(double) );
      }
      else
      {
        factor = 0;
        fout.write( reinterpret_cast<char*>( &factor ), sizeof(double) );
      }
      //Report progress
      prog.report();

    }
    fout.close();
  }
コード例 #12
0
ファイル: InstrumentActor.cpp プロジェクト: stothe2/mantid
/**
 * Recalculate the detector colors based on the integrated values in m_specIntegrs and
 * the masking information in ....
 */
void InstrumentActor::resetColors()
{
    QwtDoubleInterval qwtInterval(m_DataMinScaleValue,m_DataMaxScaleValue);
    m_colors.resize(m_specIntegrs.size());

    auto sharedWorkspace = getWorkspace();

    Instrument_const_sptr inst = getInstrument();
    IMaskWorkspace_sptr mask = getMaskWorkspaceIfExists();

    //PARALLEL_FOR1(m_workspace)
    for (int iwi=0; iwi < int(m_specIntegrs.size()); iwi++)
    {
        size_t wi = size_t(iwi);
        double integratedValue = m_specIntegrs[wi];
        try
        {
            // Find if the detector is masked
            const std::set<detid_t>& dets = sharedWorkspace->getSpectrum(wi)->getDetectorIDs();
            bool masked = false;

            if ( mask )
            {
                masked = mask->isMasked( dets );
            }
            else
            {
                masked = inst->isDetectorMasked(dets);
            }

            if (masked)
            {
                m_colors[wi] = m_maskedColor;
            }
            else
            {
                QRgb color = m_colorMap.rgb(qwtInterval,integratedValue);
                m_colors[wi] = GLColor(qRed(color), qGreen(color), qBlue(color));
            }
        }
        catch(NotFoundError &)
        {
            m_colors[wi] = m_failedColor;
            continue;
        }
    }
    if (m_scene.getNumberOfActors() > 0)
    {
        if (auto actor = dynamic_cast<CompAssemblyActor*>(m_scene.getActor(0))) {
            actor->setColors();
            invalidateDisplayLists();
        }
    }
    emit colorMapChanged();
}
コード例 #13
0
ファイル: AnvredCorrection.cpp プロジェクト: BigShows/mantid
  void AnvredCorrection::scale_init(IDetector_const_sptr det, Instrument_const_sptr inst, int& bank, double& L2, double& depth, double& pathlength, std::string bankName)
  {
	bankName = det->getParent()->getParent()->getName();
	std::string bankNameStr = bankName;
	// Take out the "bank" part of the bank name and convert to an int
	bankNameStr.erase(remove_if(bankNameStr.begin(), bankNameStr.end(), not1(std::ptr_fun (::isdigit))), bankNameStr.end());
	Strings::convert(bankNameStr, bank);
	IComponent_const_sptr sample = inst->getSample();
	double cosA = inst->getComponentByName(bankName)->getDistance(*sample) / L2;
	pathlength = depth / cosA;
  }
コード例 #14
0
  void EstimatePDDetectorResolution::retrieveInstrumentParameters()
  {
#if 0
    // Call SolidAngle to get solid angles for all detectors
    Algorithm_sptr calsolidangle = createChildAlgorithm("SolidAngle", -1, -1, true);
    calsolidangle->initialize();

    calsolidangle->setProperty("InputWorkspace", m_inputWS);

    calsolidangle->execute();
    if (!calsolidangle->isExecuted())
      throw runtime_error("Unable to run solid angle. ");

    m_solidangleWS = calsolidangle->getProperty("OutputWorkspace");
    if (!m_solidangleWS)
      throw runtime_error("Unable to get solid angle workspace from SolidAngle(). ");


    size_t numspec = m_solidangleWS->getNumberHistograms();
    for (size_t i = 0; i < numspec; ++i)
      g_log.debug() << "[DB]: " << m_solidangleWS->readY(i)[0] << "\n";
#endif

    // Calculate centre neutron velocity
    Property* cwlproperty = m_inputWS->run().getProperty("LambdaRequest");
    if (!cwlproperty)
      throw runtime_error("Unable to locate property LambdaRequest as central wavelength. ");
    TimeSeriesProperty<double>* cwltimeseries = dynamic_cast<TimeSeriesProperty<double>* >(cwlproperty);
    if (!cwltimeseries)
      throw runtime_error("LambdaReqeust is not a TimeSeriesProperty in double. ");
    if (cwltimeseries->size() != 1)
      throw runtime_error("LambdaRequest should contain 1 and only 1 entry. ");

    double centrewavelength = cwltimeseries->nthValue(0);
    string unit = cwltimeseries->units();
    if (unit.compare("Angstrom") == 0)
      centrewavelength *= 1.0E-10;
    else
      throw runtime_error("Unit is not recognized");

    m_centreVelocity = PhysicalConstants::h/PhysicalConstants::NeutronMass/centrewavelength;
    g_log.notice() << "Centre wavelength = " << centrewavelength << ", Centre neutron velocity = " << m_centreVelocity << "\n";

    // Calcualte L1 sample to source
    Instrument_const_sptr instrument = m_inputWS->getInstrument();
    V3D samplepos = instrument->getSample()->getPos();
    V3D sourcepos = instrument->getSource()->getPos();
    m_L1 = samplepos.distance(sourcepos);
    g_log.notice() << "L1 = " << m_L1 << "\n";

    return;
  }
コード例 #15
0
void PeakIntegration::retrieveProperties() {
  inputW = getProperty("InputWorkspace");
  if (inputW->readY(0).size() <= 1)
    throw std::runtime_error("Must Rebin data with more than 1 bin");
  // Check if detectors are RectangularDetectors
  Instrument_const_sptr inst = inputW->getInstrument();
  boost::shared_ptr<RectangularDetector> det;
  for (int i = 0; i < inst->nelements(); i++) {
    det = boost::dynamic_pointer_cast<RectangularDetector>((*inst)[i]);
    if (det)
      break;
  }
}
コード例 #16
0
ファイル: LoadIsawPeaks.cpp プロジェクト: BigShows/mantid
  int LoadIsawPeaks::findPixelID(Instrument_const_sptr inst, std::string bankName, int col, int row)
  {
	  boost::shared_ptr<const IComponent> parent = inst->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::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 col0 = (col%2==0 ? col/2+75 : (col-1)/2);
          boost::shared_ptr<const Geometry::ICompAssembly> asmb2 = boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(children[col0]);
          std::vector<Geometry::IComponent_const_sptr> grandchildren;
          asmb2->getChildren(grandchildren,false);
          Geometry::IComponent_const_sptr first = grandchildren[row-1];
          Geometry::IDetector_const_sptr det = boost::dynamic_pointer_cast<const Geometry::IDetector>(first);
		  return det->getID();
	  }
  }
コード例 #17
0
/** Creates a mapping based on a fixed number of groups for a given instrument
 *component
 *
 * @param compName Name of component in instrument
 * @param numGroups Number of groups to group detectors into
 * @param inst Pointer to instrument
 * @param prog Progress reporter
 * @returns :: Map of detector IDs to group number
 */
std::map<detid_t, int> makeGroupingByNumGroups(const std::string compName,
                                               int numGroups,
                                               Instrument_const_sptr inst,
                                               Progress &prog) {
  std::map<detid_t, int> detIDtoGroup;

  // Get detectors for given instument component
  std::vector<IDetector_const_sptr> detectors;
  inst->getDetectorsInBank(detectors, compName);
  size_t numDetectors = detectors.size();

  // Sanity check for following calculation
  if (numGroups > static_cast<int>(numDetectors))
    throw std::runtime_error("Number of groups must be less than or "
                             "equal to number of detectors");

  // Calculate number of detectors per group
  int detectorsPerGroup = static_cast<int>(numDetectors) / numGroups;

  // Map detectors to group
  for (unsigned int detIndex = 0; detIndex < numDetectors; detIndex++) {
    int detectorID = detectors[detIndex]->getID();
    int groupNum = (detIndex / detectorsPerGroup) + 1;

    // Ignore any detectors the do not fit nicely into the group divisions
    if (groupNum <= numGroups)
      detIDtoGroup[detectorID] = groupNum;

    prog.report();
  }
  return detIDtoGroup;
}
コード例 #18
0
/**
 * Returns the value associated to a parameter name in the IDF
 * @param parameterName :: parameter name in the IDF
 * @return the value associated to the parameter name
 */
std::string DetectorEfficiencyCorUser::getValFromInstrumentDef(
    const std::string &parameterName) {

  const ParameterMap &pmap = m_inputWS->constInstrumentParameters();
  Instrument_const_sptr instrument = m_inputWS->getInstrument();
  Parameter_sptr par =
      pmap.getRecursive(instrument->getChild(0).get(), parameterName);
  if (par) {
    std::string ret = par->asString();
    g_log.debug() << "Parsed parameter " << parameterName << ": " << ret
                  << "\n";
    return ret;
  } else {
    throw Kernel::Exception::InstrumentDefinitionError(
        "There is no <" + parameterName + "> in the instrument definition!");
  }
}
コード例 #19
0
ファイル: IkedaCarpenterPV.cpp プロジェクト: dezed/mantid
/** Method for updating m_waveLength.
 *  If size of m_waveLength is equal to number of data (for a new instance of
 *this
 *  class this vector is empty initially) then don't recalculate it.
 *
 *  @param xValues :: x values
 *  @param nData :: length of xValues
 */
void IkedaCarpenterPV::calWavelengthAtEachDataPoint(const double *xValues,
                                                    const size_t &nData) const {
  // if wavelength vector already have the right size no need for resizing it
  // further we make the assumption that no need to recalculate this vector if
  // it already has the right size

  if (m_waveLength.size() != nData) {
    m_waveLength.resize(nData);

    Mantid::Kernel::Unit_sptr wavelength =
        Mantid::Kernel::UnitFactory::Instance().create("Wavelength");
    for (size_t i = 0; i < nData; i++) {
      m_waveLength[i] = xValues[i];
    }

    // note if a version of convertValue was added which allows a double* as
    // first argument
    // then could avoid copying above plus only have to resize m_wavelength when
    // its size smaller than nData
    API::MatrixWorkspace_const_sptr mws = getMatrixWorkspace();
    if (mws) {
      API::MatrixWorkspace_const_sptr mws = getMatrixWorkspace();
      Instrument_const_sptr instrument = mws->getInstrument();
      Geometry::IComponent_const_sptr sample = instrument->getSample();
      if (sample != nullptr) {
        convertValue(m_waveLength, wavelength, mws, m_workspaceIndex);
      } else {
        g_log.warning()
            << "No sample set for instrument in workspace.\n"
            << "Can't calculate wavelength in IkedaCarpenter.\n"
            << "Default all wavelengths to one.\n"
            << "Solution is to load appropriate instrument into workspace.\n";
        for (size_t i = 0; i < nData; i++)
          m_waveLength[i] = 1.0;
      }
    } else {
      g_log.warning() << "Workspace not set.\n"
                      << "Can't calculate wavelength in IkedaCarpenter.\n"
                      << "Default all wavelengths to one.\n"
                      << "Solution call setMatrixWorkspace() for function.\n";
      for (size_t i = 0; i < nData; i++)
        m_waveLength[i] = 1.0;
    }
  }
}
コード例 #20
0
/** Extract a spectrum from the Efficiencies workspace as a 1D workspace.
 * @param label :: A label of the spectrum to extract.
 * @return :: A workspace with a single spectrum.
 */
boost::shared_ptr<Mantid::API::MatrixWorkspace>
PolarizationCorrectionFredrikze::getEfficiencyWorkspace(
    const std::string &label) {
  MatrixWorkspace_sptr efficiencies = getProperty(efficienciesLabel);
  auto const &axis = dynamic_cast<TextAxis &>(*efficiencies->getAxis(1));
  size_t index = axis.length();
  for (size_t i = 0; i < axis.length(); ++i) {
    if (axis.label(i) == label) {
      index = i;
      break;
    }
  }

  if (index == axis.length()) {
    // Check if we need to fetch polarization parameters from the instrument's
    // parameters
    static std::map<std::string, std::string> loadableProperties{
        {crhoLabel, "crho"},
        {cppLabel, "cPp"},
        {cApLabel, "cAp"},
        {cAlphaLabel, "calpha"}};
    WorkspaceGroup_sptr inWS = getProperty("InputWorkspace");
    Instrument_const_sptr instrument = fetchInstrument(inWS.get());
    auto vals = instrument->getStringParameter(loadableProperties[label]);
    if (vals.empty()) {
      throw std::invalid_argument("Efficiencey property not found: " + label);
    }
    auto extract = createChildAlgorithm("CreatePolarizationEfficiencies");
    extract->initialize();
    extract->setProperty("InputWorkspace", efficiencies);
    extract->setProperty(label, vals.front());
    extract->execute();
    MatrixWorkspace_sptr outWS = extract->getProperty("OutputWorkspace");
    return outWS;
  } else {
    auto extract = createChildAlgorithm("ExtractSingleSpectrum");
    extract->initialize();
    extract->setProperty("InputWorkspace", efficiencies);
    extract->setProperty("WorkspaceIndex", static_cast<int>(index));
    extract->execute();
    MatrixWorkspace_sptr outWS = extract->getProperty("OutputWorkspace");
    return outWS;
  }
}
コード例 #21
0
ファイル: LoadDspacemap.cpp プロジェクト: spaceyatom/mantid
/**
 * Make a map of the conversion factors between tof and D-spacing
 * for all pixel IDs in a workspace.
 *
 * @param DFileName :: name of dspacemap file
 * @param offsetsWS :: OffsetsWorkspace to be filled.
 */
void LoadDspacemap::CalculateOffsetsFromDSpacemapFile(
    const std::string DFileName,
    Mantid::DataObjects::OffsetsWorkspace_sptr offsetsWS) {
  // Get a pointer to the instrument contained in the workspace
  Instrument_const_sptr instrument = offsetsWS->getInstrument();
  double l1;
  Kernel::V3D beamline, samplePos;
  double beamline_norm;
  instrument->getInstrumentParameters(l1, beamline, beamline_norm, samplePos);

  // To get all the detector ID's
  detid2det_map allDetectors;
  instrument->getDetectors(allDetectors);

  // Read in the POWGEN-style Dspace mapping file
  const char *filename = DFileName.c_str();
  std::ifstream fin(filename, std::ios_base::in | std::ios_base::binary);

  std::vector<double> dspace;
  double read;
  while (!fin.eof()) {
    fin.read(reinterpret_cast<char *>(&read), sizeof read);
    // Factor of 10 between ISAW and Mantid
    read *= 10.;
    dspace.push_back(read);
  }

  detid2det_map::const_iterator it;
  for (it = allDetectors.begin(); it != allDetectors.end(); ++it) {
    detid_t detectorID = it->first;
    Geometry::IDetector_const_sptr det = it->second;

    // Compute the factor
    double offset = 0.0;
    double factor = Instrument::calcConversion(l1, beamline, beamline_norm,
                                               samplePos, det, offset);
    offset = dspace[detectorID] / factor - 1.0;
    // Save in the map
    try {
      offsetsWS->setValue(detectorID, offset);
    } catch (std::invalid_argument &) {
    }
  }
}
コード例 #22
0
/**
 * @param offsetsWS
 * @param index
 * @return The offset adjusted value of DIFC
 */
double calculateDIFC(OffsetsWorkspace_const_sptr offsetsWS, const size_t index) {
    Instrument_const_sptr instrument = offsetsWS->getInstrument();

    const detid_t detid = getDetID(offsetsWS, index);
    const double offset = getOffset(offsetsWS, detid);

    double l1;
    Kernel::V3D beamline, samplePos;
    double beamline_norm;
    instrument->getInstrumentParameters(l1, beamline, beamline_norm, samplePos);

    Geometry::IDetector_const_sptr detector = instrument->getDetector(detid);

    // the factor returned is what is needed to convert TOF->d-spacing
    // the table is supposed to be filled with DIFC which goes the other way
    const double factor = Instrument::calcConversion(l1, beamline, beamline_norm,
                                      samplePos, detector, offset);
    return 1./factor;
}
コード例 #23
0
    /**
     * Update the list of analysers based on an instrument workspace.
     *
     * @param ws Instrument workspace
     * @return If the workspace contained valid analysers
     */
    bool IndirectInstrumentConfig::updateAnalysersList(MatrixWorkspace_sptr ws)
    {
      if(!ws)
        return false;

      QList<QPair<QString, QString>> instrumentModes;
      Instrument_const_sptr instrument = ws->getInstrument();

      std::vector<std::string> ipfAnalysers = instrument->getStringParameter("analysers");
      QStringList analysers;
      if(ipfAnalysers.size() > 0)
        analysers = QString::fromStdString(ipfAnalysers[0]).split(",");

      // Do not try to display analysers if there are none
      if(analysers.size() == 0)
        return false;

      for(auto it = analysers.begin(); it != analysers.end(); ++it)
      {
        QString analyser = *it;
        std::string ipfReflections = instrument->getStringParameter("refl-" + analyser.toStdString())[0];
        QStringList reflections = QString::fromStdString(ipfReflections).split(",");

        if(m_removeDiffraction && analyser == "diffraction")
          continue;

        if(m_forceDiffraction && analyser != "diffraction")
          continue;

        if(reflections.size() > 0)
        {
          QVariant data = QVariant(reflections);
          m_uiForm.cbAnalyser->addItem(analyser, data);
        }
        else
        {
          m_uiForm.cbAnalyser->addItem(analyser);
        }
      }

      return true;
    }
コード例 #24
0
void EstimateResolutionDiffraction::retrieveInstrumentParameters() {
    double centrewavelength = getWavelength();
    g_log.notice() << "Centre wavelength = " << centrewavelength << " Angstrom\n";
    if (centrewavelength > WAVELENGTH_MAX) {
        throw runtime_error("unphysical wavelength used");
    }

    // Calculate centre neutron velocity
    m_centreVelocity = WAVELENGTH_TO_VELOCITY / centrewavelength;
    g_log.notice() << "Centre neutron velocity = " << m_centreVelocity << "\n";

    // Calculate L1 sample to source
    Instrument_const_sptr instrument = m_inputWS->getInstrument();
    V3D samplepos = instrument->getSample()->getPos();
    V3D sourcepos = instrument->getSource()->getPos();
    m_L1 = samplepos.distance(sourcepos);
    g_log.notice() << "L1 = " << m_L1 << "\n";

    return;
}
コード例 #25
0
ファイル: IO_MuonGrouping.cpp プロジェクト: nimgould/mantid
/**
 * Returns a "dummy" grouping which a single group with all the detectors in it.
 * @param instrument :: Instrument we want a dummy grouping for
 * @return Grouping information
 */
boost::shared_ptr<Grouping> getDummyGrouping(Instrument_const_sptr instrument)
{
  // Group with all the detectors
  std::ostringstream all;
  all << "1-" << instrument->getNumberDetectors();

  auto dummyGrouping = boost::make_shared<Grouping>();
  dummyGrouping->description = "Dummy grouping";
  dummyGrouping->groupNames.push_back("all");
  dummyGrouping->groups.push_back(all.str());
  return dummyGrouping;
}
コード例 #26
0
PoldiDeadWireDecorator::PoldiDeadWireDecorator(Instrument_const_sptr poldiInstrument, boost::shared_ptr<PoldiAbstractDetector> detector) :
    PoldiDetectorDecorator(detector),
    m_deadWireSet(),
    m_goodElements()
{
    setDecoratedDetector(detector);

    std::vector<detid_t> allDetectorIds = poldiInstrument->getDetectorIDs();
    std::vector<detid_t> deadDetectorIds(allDetectorIds.size());

    std::vector<detid_t>::iterator endIterator = std::remove_copy_if(allDetectorIds.begin(), allDetectorIds.end(), deadDetectorIds.begin(), boost::bind<bool>(&PoldiDeadWireDecorator::detectorIsNotMasked, poldiInstrument, _1));
    deadDetectorIds.resize(std::distance(deadDetectorIds.begin(), endIterator));

    setDeadWires(std::set<int>(deadDetectorIds.begin(), deadDetectorIds.end()));
}
コード例 #27
0
ファイル: InstrumentActor.cpp プロジェクト: stothe2/mantid
/**
 * Constructor. Creates a tree of GLActors. Each actor is responsible for displaying insrument components in 3D.
 * Some of the components have "pick ID" assigned to them. Pick IDs can be uniquely converted to a RGB colour value
 * which in turn can be used for picking the component from the screen.
 * @param wsName :: Workspace name
 * @param autoscaling :: True to start with autoscaling option on. If on the min and max of
 *   the colormap scale are defined by the min and max of the data.
 * @param scaleMin :: Minimum value of the colormap scale. Used to assign detector colours. Ignored if autoscaling == true.
 * @param scaleMax :: Maximum value of the colormap scale. Used to assign detector colours. Ignored if autoscaling == true.
 */
InstrumentActor::InstrumentActor(const QString &wsName, bool autoscaling, double scaleMin, double scaleMax):
    m_workspace(AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(wsName.toStdString())),
    m_ragged(true),
    m_autoscaling(autoscaling),
    m_defaultPos(),
    m_maskedColor(100,100,100),
    m_failedColor(200,200,200)
{
    // settings
    loadSettings();

    auto sharedWorkspace = m_workspace.lock();
    if (!sharedWorkspace)
        throw std::logic_error("InstrumentActor passed a workspace that isn't a MatrixWorkspace");

    // set up the color map
    if (!m_currentColorMapFilename.isEmpty())
    {
        loadColorMap(m_currentColorMapFilename,false);
    }
    m_colorMap.changeScaleType(m_scaleType);

    // set up data ranges and colours
    setUpWorkspace(sharedWorkspace, scaleMin, scaleMax);

    Instrument_const_sptr instrument = getInstrument();

    // If the instrument is empty, maybe only having the sample and source
    const int nelements = instrument->nelements();
    if ( ( nelements == 0 ) ||
            ( nelements == 1 && ( instrument->getSource() || instrument->getSample() ) ) ||
            ( nelements == 2 && instrument->getSource() && instrument->getSample() )
       )
    {
        QMessageBox::warning(NULL,"MantidPlot - Warning","This instrument appears to contain no detectors","OK");
    }

    // this adds actors for all instrument components to the scene and fills in m_detIDs
    m_scene.addActor(new CompAssemblyActor(*this,instrument->getComponentID()));
    setupPickColors();

    if ( !m_showGuides )
    {
        // hide guide and other components
        showGuides( m_showGuides );
    }
}
コード例 #28
0
  /** Executes the algorithm
   *
   *  @throw Exception::FileError If the grouping file cannot be opened or read successfully
   *  @throw runtime_error If unable to run one of the Child Algorithms successfully
   */
  void ReadGroupsFromFile::exec()
  {
    MatrixWorkspace_const_sptr ws = getProperty("InstrumentWorkspace");

    // Get the instrument.
    Instrument_const_sptr inst = ws->getInstrument();

    // Create a copy (without the data) of the workspace - it will contain the
    Workspace2D_sptr localWorkspace =
        boost::dynamic_pointer_cast<Workspace2D>(WorkspaceFactory::Instance().create(ws, ws->getNumberHistograms(), 2, 1));
    if (!localWorkspace)
      throw std::runtime_error("Failed when creating a Workspace2D from the input!");

    const std::string groupfile=getProperty("GroupingFilename");

    if ( ! groupfile.empty() )
    {
      std::string filename(groupfile);
      std::transform(filename.begin(), filename.end(), filename.begin(), tolower);
      if ( filename.find(".xml") != std::string::npos )
      {
        readXMLGroupingFile(groupfile);
      }
      else
      {
        readGroupingFile(groupfile);
      }
    }

    // Get the instrument.
    const int64_t nHist=localWorkspace->getNumberHistograms();

    // Determine whether the user wants to see unselected detectors or not
    const std::string su=getProperty("ShowUnselected");
    bool showunselected=(!su.compare("True"));
    bool success=false;

    for (int64_t i=0;i<nHist;i++)
    {
      ISpectrum * spec = localWorkspace->getSpectrum(i);
      const std::set<detid_t> & dets = spec->getDetectorIDs();
      if (dets.empty()) // Nothing
      {
        spec->dataY()[0]=0.0;
        continue;
      }
      // Find the first detector ID in the list
      calmap::const_iterator it=calibration.find(*dets.begin());
      if (it==calibration.end()) //Could not find the detector
      {
        spec->dataY()[0]=0.0;
        continue;
      }
      if (showunselected)
      {
        if (((*it).second).second==0)
          spec->dataY()[0]=0.0;
        else
          spec->dataY()[0]=static_cast<double>(((*it).second).first);
      }
      else
        spec->dataY()[0]=static_cast<double>(((*it).second).first);
      if (!success) success=true; //At least one detector is found in the cal file

    }
    progress(1);

    calibration.clear();
    if (!success) //Do some cleanup
    {
      localWorkspace.reset();
      throw std::runtime_error("Fail to found a detector in "+groupfile+" existing in instrument "+inst->getName());
    }
    setProperty("OutputWorkspace",localWorkspace);
    return;
  }
コード例 #29
0
/** Execute the algorithm.
 */
void CreateChunkingFromInstrument::exec() {
  // get the instrument
  Instrument_const_sptr inst = this->getInstrument();

  // setup the output workspace
  ITableWorkspace_sptr strategy =
      WorkspaceFactory::Instance().createTable("TableWorkspace");
  strategy->addColumn("str", "BankName");
  this->setProperty("OutputWorkspace", strategy);

  // get the correct level of grouping
  string groupLevel = this->getPropertyValue(PARAM_CHUNK_BY);
  vector<string> groupNames =
      getGroupNames(this->getPropertyValue(PARAM_CHUNK_NAMES));
  if (groupLevel.compare("All") == 0) {
    return; // nothing to do
  } else if (inst->getName().compare("SNAP") == 0 &&
             groupLevel.compare("Group") == 0) {
    groupNames.clear();
    groupNames.push_back("East");
    groupNames.push_back("West");
  }

  // set up a progress bar with the "correct" number of steps
  int maxBankNum = this->getProperty(PARAM_MAX_BANK_NUM);
  Progress progress(this, .2, 1., maxBankNum);

  // search the instrument for the bank names
  int maxRecurseDepth = this->getProperty(PARAM_MAX_RECURSE);
  map<string, vector<string>> grouping;
  // cppcheck-suppress syntaxError
    PRAGMA_OMP(parallel for schedule(dynamic, 1) )
    for (int num = 0; num < maxBankNum; ++num) {
      PARALLEL_START_INTERUPT_REGION
      ostringstream mess;
      mess << "bank" << num;
      IComponent_const_sptr comp =
          inst->getComponentByName(mess.str(), maxRecurseDepth);
      PARALLEL_CRITICAL(grouping)
      if (comp) {
        // get the name of the correct parent
        string parent;
        if (groupNames.empty()) {
          parent = parentName(comp, groupLevel);
        } else {
          parent = parentName(comp, groupNames);
        }

        // add it to the correct chunk
        if (!parent.empty()) {
          if (grouping.count(parent) == 0)
            grouping[parent] = vector<string>();

          grouping[parent].push_back(comp->getName());
        }
      }
      progress.report();
      PARALLEL_END_INTERUPT_REGION
    }
    PARALLEL_CHECK_INTERUPT_REGION

    // check to see that something happened
    if (grouping.empty())
      throw std::runtime_error("Failed to find any banks in the instrument");

    // fill in the table workspace
    for (auto group = grouping.begin(); group != grouping.end(); ++group) {
      stringstream banks;
      for (auto bank = group->second.begin(); bank != group->second.end();
           ++bank)
        banks << (*bank) << ",";

      // remove the trailing comma
      string banksStr = banks.str();
      banksStr = banksStr.substr(0, banksStr.size() - 1);

      // add it to the table
      TableRow row = strategy->appendRow();
      row << banksStr;
    }
}
コード例 #30
0
/** Executes the algorithm
 *
 *  @throw Exception::FileError If the grouping file cannot be opened or read successfully
 *  @throw runtime_error If unable to run one of the Child Algorithms successfully
 */
void CreateDummyCalFile::exec()
{
    // Get the input workspace
    MatrixWorkspace_const_sptr inputW = getProperty("InputWorkspace");
    if (!inputW)
        throw std::invalid_argument("No InputWorkspace");

    //Get some stuff from the input workspace
    Instrument_const_sptr inst = inputW->getInstrument();
    std::string instname = inst->getName();

    // Check that the instrument is in store
    // Get only the first 3 letters
    std::string instshort=instname;
    std::transform(instshort.begin(),instshort.end(),instshort.begin(),toupper);
    instshort=instshort+"_Definition.xml";
    // Determine the search directory for XML instrument definition files (IDFs)
    std::string directoryName = Kernel::ConfigService::Instance().getInstrumentDirectory();

    // Set up the DOM parser and parse xml file
    DOMParser pParser;
    Document* pDoc;
    try
    {
        pDoc = pParser.parse(directoryName+instshort);
    }
    catch(...)
    {
        g_log.error("Unable to parse file " + m_filename);
        throw Kernel::Exception::FileError("Unable to parse File:" , m_filename);
    }
    // Get pointer to root element
    Element* pRootElem = pDoc->documentElement();
    if ( !pRootElem->hasChildNodes() )
    {
        g_log.error("XML file: " + m_filename + "contains no root element.");
        throw Kernel::Exception::InstrumentDefinitionError("No root element in XML instrument file", m_filename);
    }

    // Handle used in the singleton constructor for instrument file should append the value
    // of the last-modified tag inside the file to determine if it is already in memory so that
    // changes to the instrument file will cause file to be reloaded.
    auto temp = instshort + pRootElem->getAttribute("last-modified");// Generate the mangled name by hand (old-style)

    // If instrument not in store, insult the user
    if (!API::InstrumentDataService::Instance().doesExist(temp))
    {
        Mantid::Geometry::IDFObject idf(directoryName+instshort);
        temp = idf.getMangledName(); // new style.
        if (!API::InstrumentDataService::Instance().doesExist(temp))
        {
            g_log.error("Instrument "+instshort+" is not present in data store.");
            throw std::runtime_error("Instrument "+instshort+" is not present in data store.");
        }
    }

    // Get the names of groups
    groups=instname;

    // Split the names of the group and insert in a vector, throw if group empty
    std::vector<std::string> vgroups;
    boost::split( vgroups, instname, boost::algorithm::detail::is_any_ofF<char>(",/*"));
    if (vgroups.empty())
    {
        g_log.error("Could not determine group names. Group names should be separated by / or ,");
        throw std::runtime_error("Could not determine group names. Group names should be separated by / or ,");
    }

    // Assign incremental number to each group
    std::map<std::string,int> group_map;
    int index=0;
    for (std::vector<std::string>::const_iterator it=vgroups.begin(); it!=vgroups.end(); ++it)
        group_map[(*it)]=++index;

    // Not needed anymore
    vgroups.clear();

    // Find Detectors that belong to groups
    typedef boost::shared_ptr<const Geometry::ICompAssembly> sptr_ICompAss;
    typedef boost::shared_ptr<const Geometry::IComponent> sptr_IComp;
    typedef boost::shared_ptr<const Geometry::IDetector> sptr_IDet;
    std::queue< std::pair<sptr_ICompAss,int> > assemblies;
    sptr_ICompAss current=boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(inst);
    sptr_IDet currentDet;
    sptr_IComp currentIComp;
    sptr_ICompAss currentchild;

    int top_group, child_group;

    if (current.get())
    {
        top_group=group_map[current->getName()]; // Return 0 if not in map
        assemblies.push(std::make_pair(current,top_group));
    }

    std::string filename=getProperty("CalFilename");

    // Plan to overwrite file, so do not check if it exists
    bool overwrite=false;

    int number=0;
    Progress prog(this,0.0,0.8,assemblies.size());
    while(!assemblies.empty()) //Travel the tree from the instrument point
    {
        current=assemblies.front().first;
        top_group=assemblies.front().second;
        assemblies.pop();
        int nchilds=current->nelements();
        if (nchilds!=0)
        {
            for (int i=0; i<nchilds; ++i)
            {
                currentIComp=(*(current.get()))[i]; // Get child
                currentDet=boost::dynamic_pointer_cast<const Geometry::IDetector>(currentIComp);
                if (currentDet.get())// Is detector
                {
                    if (overwrite) // Map will contains udet as the key
                        instrcalib[currentDet->getID()]=std::make_pair(number++,top_group);
                    else          // Map will contains the entry number as the key
                        instrcalib[number++]=std::make_pair(currentDet->getID(),top_group);
                }
                else // Is an assembly, push in the queue
                {
                    currentchild=boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(currentIComp);
                    if (currentchild.get())
                    {
                        child_group=group_map[currentchild->getName()];
                        if (child_group==0)
                            child_group=top_group;
                        assemblies.push(std::make_pair(currentchild,child_group));
                    }
                }
            }
        }
        prog.report();
    }
    // Write the results in a file
    saveGroupingFile(filename,overwrite);
    progress(0.2);
    return;
}