CFEL - ASG Software Suite  2.5.0
CASS
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
cass::pp208 Class Reference

find bragg peaks and store them in list More...

#include <hitfinder.h>

+ Inheritance diagram for cass::pp208:
+ Collaboration diagram for cass::pp208:

Public Member Functions

 pp208 (const name_t &name)
 constructor More...
 
virtual void process (const CASSEvent &, result_t &)
 process event More...
 
virtual void loadSettings (size_t)
 load the settings of this pp More...
 
- Public Member Functions inherited from cass::Processor
 Processor (const name_t &name)
 constructor More...
 
virtual ~Processor ()
 virtual destructor More...
 
virtual void processEvent (const CASSEvent &event)
 process the event More...
 
virtual const result_tresult (const CASSEvent::id_t eventid=0)
 retrieve a result for a given id. More...
 
virtual void releaseEvent (const CASSEvent &event)
 tell the list that the result for event can be overwritten More...
 
result_t::shared_pointer resultCopy (const uint64_t eventid)
 retrieve histogram for id More...
 
virtual void load ()
 load the general settings More...
 
virtual void aboutToQuit ()
 function that will be called when the processor is about to be deleted More...
 
const names_tdependencies ()
 Define all processors keys a processor depends on. More...
 
void clearDependencies ()
 clear the dependenies More...
 
void clearHistograms ()
 clear the histograms More...
 
virtual void processCommand (std::string command)
 process command in pp More...
 
const name_t name () const
 retrieve the name of this processor More...
 
bool hide () const
 retrieve the hide flag of this processor More...
 
const std::string & comment () const
 retrieve the comment of this processor More...
 

Protected Types

enum  ColumnNames {
  Intensity = 0, centroidColumn = 1, centroidRow = 2, nbrOfPixels = 3,
  SignalToNoiseHighestPixel = 4, Index = 5, Column = 6, Row = 7,
  LocalBackground = 8, LocalBackgroundDeviation = 9, MaxRadius = 10, MinRadius = 11,
  MaxADU = 12, nUpOutliers = 13, Resolution = 14, SignalToNoiseSpot = 15,
  nbrOf
}
 enum describing the contents of the resulting table More...
 
typedef result_t::storage_t table_t
 definition of the table More...
 
typedef result_t::storage_t::value_type pixelval_t
 define the type of the pixel in image More...
 
typedef CummulativeStatisticsNoOutlier< pixelval_tstat_t
 define the type of statistics used More...
 
typedef int64_t index_t
 define the index in the image More...
 
typedef std::pair< index_t, index_tshape_t
 define the shape of the image More...
 
typedef std::vector< index_tneighbourList_t
 define the list of neighbours More...
 

Protected Member Functions

int getBoxStatistics (result_t::const_iterator pixel, const index_t linIdx, const shape_t &box, stat_t &stat)
 retrieve the box statistics More...
 
int isNotHighest (result_t::const_iterator pixel, const index_t linIdx, shape_t box, stat_t &stat)
 check if pixel is not highest within box More...
 
double lambdaFromConstant (const CASSEvent::id_t &)
 retrieve the constant wavelength More...
 
double lambdaFromProcessor (const CASSEvent::id_t &id)
 retrieve the wavelength from the processor More...
 
double distanceFromConstant (const CASSEvent::id_t &)
 retrieve the constant detector distance More...
 
double distanceFromProcessor (const CASSEvent::id_t &id)
 retrieve the detector distance from the processor More...
 
pixelval_t thresholdFromProcessor (const CASSEvent::id_t &id)
 retrieve the threshold from the processor More...
 
pixelval_t thresholdFromConstant (const CASSEvent::id_t &id)
 retrieve the threshold constant More...
 
- Protected Member Functions inherited from cass::Processor
virtual void createHistList (result_t::shared_pointer result)
 create result list. More...
 
void setupGeneral ()
 general setup of the processor More...
 
bool setupCondition (bool defaultConditionType=true)
 setup the condition. More...
 
shared_pointer setupDependency (const std::string &depVarName, const name_t &name="")
 setup the dependecy. More...
 

Protected Attributes

shared_pointer _imagePP
 processor containing the image to find the bragg peaks in More...
 
shape_t _box
 the size of the box within which the peak should lie More...
 
shape_t _section
 size of a image section More...
 
shape_t _imageShape
 size of the incomming image More...
 
stat_t::value_type _minSnr
 minimum Signal to Noise Ratio thats is needed for a pixel to be an outlier More...
 
float _minRatio
 minimum ratio of nbr of points used for statistics to nbr of outliers More...
 
stat_t::count_type _minNbrPixels
 the minimum nbr of pixels in the bragg peak More...
 
neighbourList_t _neighbourOffsets
 the list of offsets to next neighbours More...
 
std::vector< double > _src2labradius
 the conversion table from raw to lab More...
 
double _wavelength
 the wavelength in case its fixed More...
 
shared_pointer _wavelengthPP
 pp containing wavelength in case its not fixed More...
 
std::tr1::function< double(const CASSEvent::id_t &)> _getLambda
 function that gets the wavelength More...
 
double _detdist
 the detector distance in case its fixed More...
 
shared_pointer _detdistPP
 pp containing detector distance in case its not fixed More...
 
std::tr1::function< double(const CASSEvent::id_t &)> _getDistance
 function that gets the detectordistance More...
 
pixelval_t _threshold
 pixel threshold to be exceeded More...
 
shared_pointer _threshPP
 pp containing threshold in case its not fixed More...
 
std::tr1::function< pixelval_t(const CASSEvent::id_t &)> _thresh
 function that gets the detectordistance More...
 
- Protected Attributes inherited from cass::Processor
const name_t _name
 the processors name More...
 
bool _hide
 flag to tell whether this pp should be hidden in the dropdown list More...
 
std::string _comment
 optional comment that one can add to a processor. More...
 
CachedList _resultList
 the list of results More...
 
names_t _dependencies
 the list of dependencies More...
 
shared_pointer _condition
 pointer to the processor that will contain the condition More...
 

Additional Inherited Members

- Public Types inherited from cass::Processor
typedef std::tr1::shared_ptr< Processorshared_pointer
 a shared pointer of this More...
 
typedef std::string name_t
 define the name type More...
 
typedef std::list< name_tnames_t
 define the list of names More...
 
typedef CachedList::item_type result_t
 define the results More...
 
typedef CachedList::item_sp resultsp_t
 define the shared pointer to the result More...
 

Detailed Description

find bragg peaks and store them in list

Available PostProcessors:
"208": find bragg peaks and store them in list

Finds bragg peaks by checking how many pixels that are connected are above the given singal to noise ratio. The mean and standart deviation for calculating the SNR is determined by a local box size. Here the statistics is cleaned from the outliers so that pixels that are potentially part of the peak are not included in the background and stdv calculation. If the ratio between outliers of the distribution and pixel that are part of the distribution does not satisfy the user setting, the box size will be increased and the process to determine the local background and std is repeated.

This algorithm was inspired by an algorithm described in Zhang et al. J. Appl. Cryst. (2006). 39, 112-119 [ doi:10.1107/S0021889805040677 ]

See also
Processor for a list of all commonly available cass.ini settings.
User definable Parameters:

Processor/%name%/{ImageName}
the processor name that contain the 2d histogram. Default is "blubb".

Processor/%name%/{SectionSizeX|SectionSizeY}
Size of the subsection of the image. Default is 1024|512.

Processor/%name%/{BraggPeakDiameter}
Minimum Diameter of a Bragg Peak. Used for determining the optimal box size and nbr of pixels in the Bragg Peak. Default is 2.

Processor/%name%/{MinRatio}
The minimum ratio of pixel that are outliers of the distribution in the box to the pixels that are part of the distribution in the box. 3 mean that there have to be at least 3 times as meany pixels that are part of the distribution than outliers of the distribution. Default is 3.

Processor/%name%/{Threshold}
Threshold of pixel in adu to be exeeded. Can also be the name of a Processor that contains the Threshold value.

Processor/%name%/{MinSignalToNoiseRatio}
Signal to noise ratio of a pixel. Value needs to be exceeded in order for the pixel to be part of a bragg peak. Default is 4.

Processor/%name%/{MinNbrPixels}
Minimum Nbr of Pixels to be part of a Bragg Peak. Default is determined by BraggPeakRadius. $ nbr = (2 \times BraggPeakRadius)^2 $

Processor/%name%/{BoxSizeX|BoxSizeY}
col (x) and rows (y) of the box that is used for determining the background. The box is going from -BoxSizeX ... BoxSizeX in x and same in y. Default is determined by the BraggPeakRadius. $ size = \sqrt{\pi} \times BraggPeakRadius $

Processor/%name%/{GeometryFilename}
The geom file to use. Default is "wrong_file" in which case the resolution will be calculated completely wrong

Processor/%name%/{ConvertCheetahToCASSLayout}
Set this true if the geom file is for a cheetah layout of the data, but the image in ImageName is the image in CASS layout.

Processor/%name%/{Wavelength_A}
The wavelength in Angstroem. Can also be the name of a Processor that contains the Wavelength. Default is 1.

Processor/%name%/{DetectorDistance_m}
The detector distance in m. Can also be the name of a Processor that contains the detector distance. Default is 60e-2.

Processor/%name%/{PixelSize_m}
The pixel size in m. Default is 109.92-6

Author
Lutz Foucar

Definition at line 387 of file hitfinder.h.

Member Typedef Documentation

typedef int64_t cass::pp208::index_t
protected

define the index in the image

Definition at line 413 of file hitfinder.h.

typedef std::vector<index_t> cass::pp208::neighbourList_t
protected

define the list of neighbours

Definition at line 419 of file hitfinder.h.

typedef result_t::storage_t::value_type cass::pp208::pixelval_t
protected

define the type of the pixel in image

Definition at line 407 of file hitfinder.h.

typedef std::pair<index_t,index_t> cass::pp208::shape_t
protected

define the shape of the image

Definition at line 416 of file hitfinder.h.

define the type of statistics used

Definition at line 410 of file hitfinder.h.

definition of the table

Definition at line 404 of file hitfinder.h.

Member Enumeration Documentation

enum cass::pp208::ColumnNames
protected

enum describing the contents of the resulting table

Enumerator
Intensity 
centroidColumn 
centroidRow 
nbrOfPixels 
SignalToNoiseHighestPixel 
Index 
Column 
Row 
LocalBackground 
LocalBackgroundDeviation 
MaxRadius 
MinRadius 
MaxADU 
nUpOutliers 
Resolution 
SignalToNoiseSpot 
nbrOf 

Definition at line 422 of file hitfinder.h.

Constructor & Destructor Documentation

pp208::pp208 ( const name_t name)

constructor

Definition at line 690 of file hitfinder.cpp.

References loadSettings().

Member Function Documentation

double cass::pp208::distanceFromConstant ( const CASSEvent::id_t )
inlineprotected

retrieve the constant detector distance

Parameters
idunused

Definition at line 489 of file hitfinder.h.

References _detdist.

Referenced by loadSettings().

double pp208::distanceFromProcessor ( const CASSEvent::id_t id)
protected

retrieve the detector distance from the processor

Parameters
idthe id of the event to get the detector distance from

Definition at line 888 of file hitfinder.cpp.

References _detdistPP.

Referenced by loadSettings().

int pp208::getBoxStatistics ( result_t::const_iterator  pixel,
const index_t  linIdx,
const shape_t box,
stat_t stat 
)
protected

retrieve the box statistics

Details:

Returns
0 when all non bad pixels have been added to the statistics. 1 if one of the pixels in the box was higher than the center pixel
Parameters
pixelconst iterator to the center pixel
linIdxthe linearized index of the pixel
boxthe shape of the box to check
statthe statistics calculator used to determine mean and stdv of pixels in box

get coordinates of pixel from the linearized index

make sure that pixel is located such that the box will not conflict with the image and section boundaries. If it does continue with next pixel

go through all pixels defined by the box from -rows ... rows, -cols ... cols

check if the current box pixel value is bigger than the center pixel value. If so skip this pixel

if its not a bad pixel add pixel to statistics

Definition at line 907 of file hitfinder.cpp.

References _imageShape, _section, cass::CummulativeStatisticsNoOutlier< Type >::addDatum(), and use.

Referenced by isNotHighest().

int pp208::isNotHighest ( result_t::const_iterator  pixel,
const index_t  linIdx,
shape_t  box,
stat_t stat 
)
protected

check if pixel is not highest within box

Details:

Returns
0 if pixel is heighest, 1 otherwise
Parameters
pixelconst iterator to the pixel to be checked
linIdxthe linearized index of the pixel
boxthe shape of the box to be checked (cols x rows)
statthe statistics calculator used to determine mean and stdv of pixels in box

check whether current pixel value is highest and generate background values

increase the box size and start over if the fraction of outliers to points used in the statistics is smaller than requested.

skip this pixel if there are not enough pixels that could potentially be part of the bragg peak.

Definition at line 946 of file hitfinder.cpp.

References _minNbrPixels, _minRatio, getBoxStatistics(), cass::CummulativeStatisticsNoOutlier< Type >::nbrPointsUsed(), cass::CummulativeStatisticsNoOutlier< Type >::nbrUpperOutliers(), cass::CummulativeStatisticsNoOutlier< Type >::reset(), and use.

Referenced by process().

double cass::pp208::lambdaFromConstant ( const CASSEvent::id_t )
inlineprotected

retrieve the constant wavelength

Parameters
idunused

Definition at line 477 of file hitfinder.h.

References _wavelength.

Referenced by loadSettings().

double pp208::lambdaFromProcessor ( const CASSEvent::id_t id)
protected

retrieve the wavelength from the processor

Parameters
idthe id of the event to get the wavelength from

Definition at line 881 of file hitfinder.cpp.

References _wavelengthPP.

Referenced by loadSettings().

void pp208::loadSettings ( size_t  )
virtual

load the settings of this pp

area of box should at least be ratio times area of peak.

\begin{eqnarray*} A_{box}&=& ratio \times A_{circle} \\ size^2 &=& ratio \times \pi r^2 \\ size &=& \sqrt{\pi r^2 \times ratio} \\ &=& r \sqrt{\pi \times ratio} \\ &=& 0.5 d \sqrt{\pi \times ratio} \end{eqnarray*}

If $ size $ goes from $-s ... s$ then $ size = 2s+1 $

\begin{eqnarray*} 2s + 1 &=& 0.5 d \sqrt{\pi \times ratio} \\ s &=& 0.5 \times 0.5 d \sqrt{\pi \times ratio} - 0.5 \\ &=& 0.25 d \sqrt{\pi \times ratio} - 0.5 \end{eqnarray*}

convert to integer

\begin{eqnarray*} (int)s &=& 0.25d\sqrt{\pi \times ratio} - 0.5 + 0.5 \\ &=& 0.25d\sqrt{\pi \times ratio} \end{eqnarray*}

min nbr of pixels should reflect the area under the bragg peak $ nbrPeaks = 0.25 \pi d $

use fixed value for wavelength if value can be converted to double, otherwise use the wavelength from the processor

use fixed value for detector distance if value can be converted to double, otherwise use the detector distance from the processor

use fixed value for threshold if value can be converted to double, otherwise use the detector distance from the processor

check if the input processors have the correct type

generate the lookuptable for the radia, if no geom file is provided, set the radia to 0

set up the neighbouroffset list

Create the result output

log what the user was requesting

Reimplemented from cass::Processor.

Definition at line 697 of file hitfinder.cpp.

References _box, cass::Processor::_condition, _detdist, _detdistPP, _getDistance, _getLambda, _imagePP, _imageShape, _minNbrPixels, _minRatio, _minSnr, _neighbourOffsets, _section, _src2labradius, _thresh, _threshold, _threshPP, _wavelength, _wavelengthPP, cass::Log::add(), QSettings::beginGroup(), cass::Processor::createHistList(), distanceFromConstant(), distanceFromProcessor(), QString::fromStdString(), cass::GeometryInfo::generateConversionMap(), cass::Log::INFO, lambdaFromConstant(), lambdaFromProcessor(), cass::Processor::name(), nbrOf, cass::Processor::setupCondition(), cass::Processor::setupDependency(), cass::Processor::setupGeneral(), cass::square(), thresholdFromConstant(), thresholdFromProcessor(), cass::toString(), QSettings::value(), cass::ACQIRIS::x, and cass::ACQIRIS::y.

Referenced by pp208().

void pp208::process ( const CASSEvent evt,
result_t result 
)
virtual

process event

clear the resulting table to fill it with the values of this image

get a table row that we can later add to the table

set up a mask that we can see which pixels have been treated

get iterators for the mask and the image with which we can iterate through the image, also rember which linearized index we are working on right now, to be able to retrieve the column and row that the current pixel corresponsed to.

check if pixel should be treated, when it has been treated before continue with the next pixel

check if pixel is above the threshold, otherwise continue with the next pixel

check if pixel is highest within box. If so, check if there are enough pixels that are not outliers. If there are not enough pixels in the box increase the box size and do the checks all over again. If the pixel is not highest within the bigger box continue with the next pixel.

retrive statistical values from the calculator

get coordinates of pixel in image from the linearized index

from the central pixel look around and see which pixels are direct part of the peak. If a neighbour is found, mask it such that one does not use it twice.

Create a list that should contain the indizes of the pixels that are part of the peak. Go through that list and check for each found neighbour whether it also has a neighbour. If so add it to the list, but only if it is part of the box.

Note
need to check if the pixel has been used after verifiying that the pixel is within the box. Otherwise in rare occasions it will happen that the pixelindex is not within the boolean array which will cause a segfault.

if the peak doesn't have enough pixels continue with next pixel

go through all pixels in the box, find out which pixels are part of the peak and centroid them. Mask all pixels in the box as checked so one does not check them again

set the peak's properties and add peak to the list of found peaks

tell that only the result of one event (image) is present in the table

Reimplemented from cass::Processor.

Definition at line 985 of file hitfinder.cpp.

References _box, _getDistance, _getLambda, _imagePP, _imageShape, _minNbrPixels, _minSnr, _neighbourOffsets, _src2labradius, _thresh, cass::Result< T >::appendRows(), cass::Result< T >::begin(), centroidColumn, centroidRow, Column, cass::Result< T >::end(), cass::CASSEvent::id(), Index, cass::ACQIRIS::integral, Intensity, isNotHighest(), LocalBackground, LocalBackgroundDeviation, cass::Result< T >::lock, MaxADU, MaxRadius, cass::CummulativeStatisticsNoOutlier< Type >::mean(), MinRadius, nbrOf, nbrOfPixels, cass::CummulativeStatisticsNoOutlier< Type >::nbrUpperOutliers(), nUpOutliers, cass::Result< T >::resetTable(), Resolution, Row, SignalToNoiseHighestPixel, SignalToNoiseSpot, cass::Result< T >::size(), and cass::CummulativeStatisticsNoOutlier< Type >::stdv().

pp208::pixelval_t pp208::thresholdFromConstant ( const CASSEvent::id_t id)
protected

retrieve the threshold constant

Parameters
idthe id of the event to get the detector distance from

Definition at line 902 of file hitfinder.cpp.

References _threshold.

Referenced by loadSettings().

pp208::pixelval_t pp208::thresholdFromProcessor ( const CASSEvent::id_t id)
protected

retrieve the threshold from the processor

Parameters
idthe id of the event to get the detector distance from

Definition at line 895 of file hitfinder.cpp.

References _threshPP.

Referenced by loadSettings().

Member Data Documentation

shape_t cass::pp208::_box
protected

the size of the box within which the peak should lie

Definition at line 511 of file hitfinder.h.

Referenced by loadSettings(), and process().

double cass::pp208::_detdist
protected

the detector distance in case its fixed

Definition at line 544 of file hitfinder.h.

Referenced by distanceFromConstant(), and loadSettings().

shared_pointer cass::pp208::_detdistPP
protected

pp containing detector distance in case its not fixed

Definition at line 547 of file hitfinder.h.

Referenced by distanceFromProcessor(), and loadSettings().

std::tr1::function<double(const CASSEvent::id_t&)> cass::pp208::_getDistance
protected

function that gets the detectordistance

Definition at line 550 of file hitfinder.h.

Referenced by loadSettings(), and process().

std::tr1::function<double(const CASSEvent::id_t&)> cass::pp208::_getLambda
protected

function that gets the wavelength

Definition at line 541 of file hitfinder.h.

Referenced by loadSettings(), and process().

shared_pointer cass::pp208::_imagePP
protected

processor containing the image to find the bragg peaks in

Definition at line 401 of file hitfinder.h.

Referenced by loadSettings(), and process().

shape_t cass::pp208::_imageShape
protected

size of the incomming image

Definition at line 517 of file hitfinder.h.

Referenced by getBoxStatistics(), loadSettings(), and process().

stat_t::count_type cass::pp208::_minNbrPixels
protected

the minimum nbr of pixels in the bragg peak

Definition at line 526 of file hitfinder.h.

Referenced by isNotHighest(), loadSettings(), and process().

float cass::pp208::_minRatio
protected

minimum ratio of nbr of points used for statistics to nbr of outliers

Definition at line 523 of file hitfinder.h.

Referenced by isNotHighest(), and loadSettings().

stat_t::value_type cass::pp208::_minSnr
protected

minimum Signal to Noise Ratio thats is needed for a pixel to be an outlier

Definition at line 520 of file hitfinder.h.

Referenced by loadSettings(), and process().

neighbourList_t cass::pp208::_neighbourOffsets
protected

the list of offsets to next neighbours

Definition at line 529 of file hitfinder.h.

Referenced by loadSettings(), and process().

shape_t cass::pp208::_section
protected

size of a image section

Definition at line 514 of file hitfinder.h.

Referenced by getBoxStatistics(), and loadSettings().

std::vector<double> cass::pp208::_src2labradius
protected

the conversion table from raw to lab

Definition at line 532 of file hitfinder.h.

Referenced by loadSettings(), and process().

std::tr1::function<pixelval_t(const CASSEvent::id_t&)> cass::pp208::_thresh
protected

function that gets the detectordistance

Definition at line 559 of file hitfinder.h.

Referenced by loadSettings(), and process().

pixelval_t cass::pp208::_threshold
protected

pixel threshold to be exceeded

Definition at line 553 of file hitfinder.h.

Referenced by loadSettings(), and thresholdFromConstant().

shared_pointer cass::pp208::_threshPP
protected

pp containing threshold in case its not fixed

Definition at line 556 of file hitfinder.h.

Referenced by loadSettings(), and thresholdFromProcessor().

double cass::pp208::_wavelength
protected

the wavelength in case its fixed

Definition at line 535 of file hitfinder.h.

Referenced by lambdaFromConstant(), and loadSettings().

shared_pointer cass::pp208::_wavelengthPP
protected

pp containing wavelength in case its not fixed

Definition at line 538 of file hitfinder.h.

Referenced by lambdaFromProcessor(), and loadSettings().


The documentation for this class was generated from the following files: