/** * Called before any fit/simulation is started to allow caching of * frequently used parameters * @param workspace :: The MD that will be used for the fit */ void TobyFitResolutionModel::preprocess( const API::IMDEventWorkspace_const_sptr &workspace) { Kernel::Timer timer; // Fill the observation cache auto iterator = workspace->createIterator(); g_log.debug() << "Starting preprocessing loop\n"; do { const size_t nevents = iterator->getNumEvents(); for (size_t i = 0; i < nevents; ++i) { uint16_t innerRunIndex = iterator->getInnerRunIndex(i); detid_t detID = iterator->getInnerDetectorID(i); const auto key = std::make_pair(innerRunIndex, detID); if (m_exptCache.find(key) == m_exptCache.end()) { API::ExperimentInfo_const_sptr expt = workspace->getExperimentInfo(innerRunIndex); m_exptCache.insert( std::make_pair(key, new CachedExperimentInfo(*expt, detID))); } } } while (iterator->next()); g_log.debug() << "Done preprocessing loop:" << timer.elapsed() << " seconds\n"; delete iterator; }
/** Get detectors' counts * @brief GetSpiceDataRawCountsFromMD::getDetCounts * @param mdws * @param runnumber :: run number of the detectors having for exporting; -1 for * all run numbers * @param detid :: detector ID for the detectors for exporting; -1 for all * detectors * @param vecX :: x-values as 2theta position of detectors to be exported; * @param vecY :: raw detector's counts * @param formX :: flag to set up vecX */ void GetSpiceDataRawCountsFromMD::getDetCounts( API::IMDEventWorkspace_const_sptr mdws, const int &runnumber, const int &detid, std::vector<double> &vecX, std::vector<double> &vecY, bool formX) { // Get sample and source position if (mdws->getNumExperimentInfo() == 0) throw std::runtime_error( "There is no ExperimentInfo object that has been set to " "input MDEventWorkspace!"); V3D samplepos; V3D sourcepos; if (formX) { ExperimentInfo_const_sptr expinfo = mdws->getExperimentInfo(0); Geometry::IComponent_const_sptr sample = expinfo->getInstrument()->getSample(); samplepos = sample->getPos(); g_log.debug() << "Sample position is " << samplepos.X() << ", " << samplepos.Y() << ", " << samplepos.Z() << "\n"; Geometry::IComponent_const_sptr source = expinfo->getInstrument()->getSource(); sourcepos = source->getPos(); g_log.debug() << "Source position is " << sourcepos.X() << "," << sourcepos.Y() << ", " << sourcepos.Z() << "\n"; vecX.clear(); } vecY.clear(); // Go through all events to find out their positions IMDIterator *mditer = mdws->createIterator(); bool scancell = true; size_t nextindex = 1; while (scancell) { // get the number of events of this cell size_t numev2 = mditer->getNumEvents(); g_log.debug() << "MDWorkspace " << mdws->name() << " Cell " << nextindex - 1 << ": Number of events = " << numev2 << " Does NEXT cell exist = " << mditer->next() << "\n"; // loop over all the events in current cell for (size_t iev = 0; iev < numev2; ++iev) { // filter out the events with uninterrested run numbers and detid // runnumber/detid < 0 indicates that all run number or all detectors will // be taken int thisrunnumber = mditer->getInnerRunIndex(iev); if (runnumber >= 0 && thisrunnumber != runnumber) continue; int thisdetid = mditer->getInnerDetectorID(iev); if (detid >= 0 && thisdetid != detid) continue; // get detector position for 2theta if (formX) { double tempx = mditer->getInnerPosition(iev, 0); double tempy = mditer->getInnerPosition(iev, 1); double tempz = mditer->getInnerPosition(iev, 2); Kernel::V3D detpos(tempx, tempy, tempz); Kernel::V3D v_det_sample = detpos - samplepos; Kernel::V3D v_sample_src = samplepos - sourcepos; double twotheta = v_det_sample.angle(v_sample_src) / M_PI * 180.; vecX.push_back(twotheta); } // add new value to vecPair double signal = mditer->getInnerSignal(iev); vecY.push_back(signal); } // ENDFOR (iev) // Advance to next cell if (mditer->next()) { // advance to next cell mditer->jumpTo(nextindex); ++nextindex; } else { // break the loop scancell = false; } } // ENDOF(while) delete (mditer); return; }