/** * Execute the align detectors algorithm for an event workspace. */ void AlignDetectors::execEvent() { // g_log.information("Processing event workspace"); // the calibration information is already read in at this point // convert the input workspace into the event workspace we already know it is const MatrixWorkspace_const_sptr matrixInputWS = this->getProperty("InputWorkspace"); EventWorkspace_const_sptr inputWS = boost::dynamic_pointer_cast<const EventWorkspace>(matrixInputWS); // generate the output workspace pointer API::MatrixWorkspace_sptr matrixOutputWS = this->getProperty("OutputWorkspace"); EventWorkspace_sptr outputWS; if (matrixOutputWS == matrixInputWS) outputWS = boost::dynamic_pointer_cast<EventWorkspace>(matrixOutputWS); else { // Make a brand new EventWorkspace outputWS = boost::dynamic_pointer_cast<EventWorkspace>( API::WorkspaceFactory::Instance().create( "EventWorkspace", inputWS->getNumberHistograms(), 2, 1)); // Copy geometry over. API::WorkspaceFactory::Instance().initializeFromParent(inputWS, outputWS, false); // You need to copy over the data as well. outputWS->copyDataFrom((*inputWS)); // Cast to the matrixOutputWS and save it matrixOutputWS = boost::dynamic_pointer_cast<MatrixWorkspace>(outputWS); this->setProperty("OutputWorkspace", matrixOutputWS); } // Set the final unit that our output workspace will have setXAxisUnits(outputWS); ConversionFactors converter = ConversionFactors(m_calibrationWS); Progress progress(this, 0.0, 1.0, m_numberOfSpectra); PARALLEL_FOR_NO_WSP_CHECK() for (int64_t i = 0; i < m_numberOfSpectra; ++i) { PARALLEL_START_INTERUPT_REGION auto toDspacing = converter.getConversionFunc( inputWS->getSpectrum(size_t(i))->getDetectorIDs()); outputWS->getEventList(i).convertTof(toDspacing); progress.report(); PARALLEL_END_INTERUPT_REGION } PARALLEL_CHECK_INTERUPT_REGION if (outputWS->getTofMin() < 0.) { std::stringstream msg; msg << "Something wrong with the calibration. Negative minimum d-spacing " "created. d_min = " << outputWS->getTofMin() << " d_max " << outputWS->getTofMax(); g_log.warning(msg.str()); } outputWS->clearMRU(); }
/** * Execute the align detectors algorithm for an event workspace. */ void AlignDetectors::execEvent() { //g_log.information("Processing event workspace"); // the calibration information is already read in at this point // convert the input workspace into the event workspace we already know it is const MatrixWorkspace_const_sptr matrixInputWS = this->getProperty("InputWorkspace"); EventWorkspace_const_sptr inputWS = boost::dynamic_pointer_cast<const EventWorkspace>(matrixInputWS); // generate the output workspace pointer API::MatrixWorkspace_sptr matrixOutputWS = this->getProperty("OutputWorkspace"); EventWorkspace_sptr outputWS; if (matrixOutputWS == matrixInputWS) outputWS = boost::dynamic_pointer_cast<EventWorkspace>(matrixOutputWS); else { //Make a brand new EventWorkspace outputWS = boost::dynamic_pointer_cast<EventWorkspace>( API::WorkspaceFactory::Instance().create("EventWorkspace", inputWS->getNumberHistograms(), 2, 1)); //Copy geometry over. API::WorkspaceFactory::Instance().initializeFromParent(inputWS, outputWS, false); //outputWS->mutableSpectraMap().clear(); //You need to copy over the data as well. outputWS->copyDataFrom( (*inputWS) ); //Cast to the matrixOutputWS and save it matrixOutputWS = boost::dynamic_pointer_cast<MatrixWorkspace>(outputWS); this->setProperty("OutputWorkspace", matrixOutputWS); } // Set the final unit that our output workspace will have outputWS->getAxis(0)->unit() = UnitFactory::Instance().create("dSpacing"); const int64_t numberOfSpectra = static_cast<int64_t>(inputWS->getNumberHistograms()); // Initialise the progress reporting object Progress progress(this,0.0,1.0,numberOfSpectra); PARALLEL_FOR_NO_WSP_CHECK() for (int64_t i = 0; i < int64_t(numberOfSpectra); ++i) { PARALLEL_START_INTERUPT_REGION // Compute the conversion factor double factor = calcConversionFromMap(this->tofToDmap, inputWS->getSpectrum(size_t(i))->getDetectorIDs()); //Perform the multiplication on all events outputWS->getEventList(i).convertTof(factor); progress.report(); PARALLEL_END_INTERUPT_REGION } PARALLEL_CHECK_INTERUPT_REGION if (outputWS->getTofMin() < 0.) { std::stringstream msg; msg << "Something wrong with the calibration. Negative minimum d-spacing created. d_min = " << outputWS->getTofMin() << " d_max " << outputWS->getTofMax(); throw std::runtime_error(msg.str()); } outputWS->clearMRU(); }