/** Read from the instrument file the dead wires and store the information in a TableWorkspace. If asked, the dead wires are removed from the data set. @param localWorkspace :: input raw data workspace, containing the information about the instrument @param outputws :: input dead wire liste workspace */ void PoldiRemoveDeadWires::runExcludWires3 ( DataObjects::Workspace2D_sptr &localWorkspace, API::ITableWorkspace_sptr &outputws ) { outputws->addColumn("int","DeadWires"); boost::shared_ptr<const Mantid::Geometry::IComponent> comp = localWorkspace->getInstrument()->getComponentByName("holder"); boost::shared_ptr<const Mantid::Geometry::ICompAssembly> bank = boost::dynamic_pointer_cast<const Mantid::Geometry::ICompAssembly>(comp); if (bank) { // Get a vector of children (recursively) std::vector<boost::shared_ptr<const Mantid::Geometry::IComponent> > children; bank->getChildren(children, true); std::vector<double> defaultDeadWires; int ewLine = 0; for (unsigned int it = 0; it < children.size(); ++it) { string wireName = children.at(it)->getName(); std::vector<boost::shared_ptr<const Mantid::Geometry::IComponent> > tyty = localWorkspace.get()->getInstrument().get()->getAllComponentsWithName(wireName); std::vector<double> tempWire = tyty[0]->getNumberParameter("excluded"); if(tempWire.size()>0) { int val = (int)tempWire[0]; g_log.debug() << "_poldi : dead wires :" << val << std::endl; defaultDeadWires.push_back(val); for(unsigned int j=0; j<m_channelsPerSpectrum; j++) { localWorkspace->maskBin(val-1,j,1); } ewLine++; TableRow t = outputws->appendRow(); t << val ; } } g_log.information() << "_poldi : dead wires set to 0 (nb:" << ewLine << ")" << std::endl; setProperty("nbExcludedWires",ewLine); } else { g_log.information() << "_poldi : no dead wire removed" << std::endl; } }
/** Auto detecte the dead wires and store the information in the TableWorkspace. If asked, the dead wires are removed from the data set. @param localWorkspace :: input raw data workspace, containing the information about the instrument @param outputws :: input dead wire liste workspace */ void PoldiRemoveDeadWires::autoRemoveDeadWires ( DataObjects::Workspace2D_sptr &localWorkspace, API::ITableWorkspace_sptr &outputws ) { double autoDeadWiresThreshold = 0; autoDeadWiresThreshold = getProperty("BadWiresThreshold"); if(!autoDeadWiresThreshold) autoDeadWiresThreshold = m_defautDWThreshold; autoDeadWiresThreshold = 1.-autoDeadWiresThreshold; // double autoDeadWiresThreshold = 1-0.4; g_log.information() << "_poldi : auto removed wires : BadWiresThreshold:" << autoDeadWiresThreshold << std::endl; int count = 0; double minValue=INFINITY; unsigned int minPos = 0; bool checkContinue = true; std::vector<double> average(this->m_numberOfSpectra); double globalAverage = 0; //compute the average intensity per spectrum for(unsigned int i=0; i<this->m_numberOfSpectra; i++) { if(!localWorkspace.get()->hasMaskedBins(i)) { average.at(i) = 0; MantidVec& tempY = localWorkspace.get()->dataY(i); for(unsigned int j=0; j<this->m_channelsPerSpectrum; j++) { average.at(i) += tempY[j]; } average.at(i) /= static_cast<double>(this->m_channelsPerSpectrum); if(average[i]<minValue) { minValue = average[i]; minPos = i; } } } g_log.debug() << "_poldi : auto removed wires : average done" << std::endl; while(checkContinue) { checkContinue = false; minValue=INFINITY; minPos = 0; int n = 0; // find the minimum average position, the most probably wrong spectra for(unsigned int i=0; i<this->m_numberOfSpectra; i++) { if(!localWorkspace.get()->hasMaskedBins(i)) { globalAverage += average[i]; n++; if(average[i]<minValue) { minValue = average[i]; minPos = i; } } } globalAverage /=n; //applied the threshold to determine if a wires should be excluded //check if the wire is not already excluded if(!localWorkspace.get()->hasMaskedBins(minPos)) { if(average[minPos]<globalAverage*autoDeadWiresThreshold) { //mask the wires for(unsigned int j=0; j<this->m_channelsPerSpectrum; j++) { localWorkspace->maskBin(minPos,j,1); } count++; checkContinue = true; TableRow t = outputws->appendRow(); t << int(minPos) ; } } //applied the threshold to determine if a wires should be excluded //check if the wire is not already excluded if(!localWorkspace.get()->hasMaskedBins(minPos)) { //check the threshold on the left unsigned int left = minPos-1; //find the first used wires on the left while(localWorkspace.get()->hasMaskedBins(left) && left>0) { left--; } if(left>0 && average[minPos]<average[left]*autoDeadWiresThreshold) { //mask the wires for(unsigned int j=0; j<this->m_channelsPerSpectrum; j++) { localWorkspace->maskBin(minPos,j,1); } count++; checkContinue = true; TableRow t = outputws->appendRow(); t << int(minPos) ; } } if(!localWorkspace.get()->hasMaskedBins(minPos)) { //check the threshold on the right unsigned int right = minPos+1; //find the first used wires on the left while(localWorkspace.get()->hasMaskedBins(right) && right<this->m_numberOfSpectra) { right++; } if(right<m_numberOfSpectra-1 && average[minPos]<average[right]*autoDeadWiresThreshold) { //mask the wires for(unsigned int j=0; j<this->m_channelsPerSpectrum; j++) { localWorkspace->maskBin(minPos,j,1); } count++; checkContinue = true; TableRow t = outputws->appendRow(); t << int(minPos) ; } } } g_log.information() << "_poldi : auto removed wires (nb:" << count << ")" << std::endl; setProperty("nbAuteDeadWires",count); }