CFEL - ASG Software Suite  2.5.0
CASS
commonmode_calculators.cpp
Go to the documentation of this file.
1 // Copyright (C) 2011 Lutz Foucar
2 
3 /**
4  * @file commonmode_calculators.cpp contains all available common mode calculators.
5  *
6  * @author Lutz Foucar
7  */
8 
9 #include <numeric>
10 #include <algorithm>
11 #include <iostream>
12 
13 #include "commonmode_calculators.h"
14 
15 #include "common_data.h"
16 #include "cass_settings.h"
17 
18 using namespace cass;
19 using namespace pixeldetector;
20 using namespace commonmode;
21 using namespace std;
22 using namespace std::tr1;
23 
24 namespace cass
25 {
26 namespace pixeldetector
27 {
28 namespace commonmode
29 {
30 
31 /** build up the list of pixels that contribute to the common mode calculation
32  *
33  * go as much pixels as told via nbrPixels. Offset correct each pixel then
34  * check whether pixel minus the initial common mode level is less than the noise
35  * if so add it to the ordered list of pixels.
36  *
37  * @param nbrPixels the number of pixel that cover the range to check for the
38  * common mode level.
39  * @param pixel iterator to the point in the frame that should be checked for
40  * the common mode level.
41  * @param offset const_iterator that starts at the position in the offset map
42  * that we are investigating
43  * @param noise const_iterator that starts at the position in the noise map that
44  * we are investigating
45  * @param mask const_iterator that starts at the position in the mask that we
46  * are interested in.
47  * @param multiplier the mulitplier to multiply to the noise value
48  * @param initialLevel the inital level of the common mode
49  * @param[out] pixels The list of pixels found in this function
50  *
51  * @author Lutz Foucar
52  */
53 void createPixelList(size_t nbrPixels,
54  Detector::frame_t::const_iterator pixel,
55  Detector::frame_t::const_iterator offset,
56  Detector::frame_t::const_iterator noise,
57  CommonData::mask_t::const_iterator mask,
58  float multiplier,
59  Detector::pixel_t initialLevel,
60  pixels_t& pixels)
61 {
62  for(size_t i(0); i<nbrPixels;++i,++pixel,++offset,++noise)
63  {
64  if (*mask)
65  {
66  Detector::pixel_t offsetcorrectedPixel(*pixel - *offset );
67  if((offsetcorrectedPixel - initialLevel) < (multiplier * *noise))
68  {
69  pixels.push_back(offsetcorrectedPixel);
70  }
71  }
72  }
73 
74 }
75 }//end namespace commonmode
76 }//end namespace pixeldetector
77 }//end namespace cass
78 
79 
80 Detector::pixel_t SimpleMeanCalculator::operator ()(Detector::frame_t::const_iterator pixel, size_t idx)const
81 {
82  Detector::frame_t::const_iterator offset(_commondata->offsetMap.begin()+idx);
83  Detector::frame_t::const_iterator noise(_commondata->noiseMap.begin()+idx);
84  CommonData::mask_t::const_iterator mask(_commondata->mask.begin()+idx);
85  Detector::pixel_t commlvl(0);
86  size_t accumulatedValues(0);
87  Detector::pixel_t pixel_wo_offset(0);
88  for(size_t i(0); i<_nbrPixels;++i,++pixel,++offset,++noise,++mask)
89  {
90  if (*mask)
91  {
92  pixel_wo_offset = *pixel - *offset;
93  if((pixel_wo_offset) < (_multiplier * *noise))
94  {
95  ++accumulatedValues;
96  commlvl += ((pixel_wo_offset - commlvl) / accumulatedValues);
97  }
98  }
99  }
100 // if (accumulatedValues < _minNbrPixels || qFuzzyCompare(commlvl,0.f))
101 // cout << _minNbrPixels << " "<< _nbrPixels<< " " << accumulatedValues<< " " <<commlvl<<endl;
102  return (_minNbrPixels < accumulatedValues ? commlvl : 0.);
103 }
104 
106 {
107  load(s);
108  s.beginGroup("SimpleMeanCommonMode");
109  _minNbrPixels = s.value("MinNbrPixels",8).toUInt();
110  s.endGroup();
111 }
112 
113 
114 Detector::pixel_t MeanCalculator::operator ()(Detector::frame_t::const_iterator pixel, size_t idx)const
115 {
116  Detector::pixel_t commonmodelevel(0);
117  pixels_t pixels;
118  createPixelList(_nbrPixels, pixel,
119  _commondata->offsetMap.begin()+idx,
120  _commondata->noiseMap.begin()+idx,
121  _commondata->mask.begin()+idx,
122  _multiplier, 0., pixels);
123  const int nbrElementsOfInterest
124  (pixels.size() - _nbrMinimumElementsToRemove - _nbrMaximumElementsToRemove);
125  const bool shouldCalcCommonMode (_minNbrPixels < nbrElementsOfInterest);
126  if (shouldCalcCommonMode)
127  {
128  sort(pixels.begin(),pixels.end());
129  pixels_t::iterator begin(pixels.begin());
130  pixels_t::iterator end(pixels.end());
131  advance(begin,_nbrMinimumElementsToRemove);
132  advance(end,-1*(_nbrMaximumElementsToRemove));
133  commonmodelevel = accumulate(begin,end,0) / static_cast<Detector::pixel_t>(distance(begin,end));
134  }
135  else
136  {
137  commonmodelevel = 0.;
138  }
139  return commonmodelevel;
140 }
141 
143 {
144  load(s);
145  s.beginGroup("MeanCommonMode");
146  _nbrMaximumElementsToRemove = s.value("NbrMaxDisregardedValues",5).toUInt();
147  _nbrMinimumElementsToRemove = s.value("NbrMinDisregardedValues",0).toUInt();
148  _minNbrPixels = s.value("MinNbrPixels",8).toUInt();
149  s.endGroup();
150 }
151 
152 Detector::pixel_t MedianCalculator::operator ()(Detector::frame_t::const_iterator pixel, size_t idx)const
153 {
154  Detector::pixel_t commonmodelevel(0);
155  pixels_t pixels;
156  createPixelList(_nbrPixels, pixel,
157  _commondata->offsetMap.begin()+idx,
158  _commondata->noiseMap.begin()+idx,
159  _commondata->mask.begin()+idx,
160  _multiplier, 0., pixels);
161  const int nbrElementsOfInterest
162  (pixels.size() - _nbrDisregardedMinimumElements - _nbrDisregardedMaximumElements);
163  const bool shouldCalcCommonMode (_minNbrPixels < nbrElementsOfInterest);
164  if (shouldCalcCommonMode)
165  {
166  size_t median = 0.5*nbrElementsOfInterest + _nbrDisregardedMinimumElements;
167  nth_element(pixels.begin(),pixels.begin()+median,pixels.end());
168  commonmodelevel = pixels[median];
169  }
170  else
171  {
172  commonmodelevel = 0.;
173  }
174  return commonmodelevel;
175 }
176 
178 {
179  load(s);
180  s.beginGroup("MedianCommonMode");
181  _nbrDisregardedMaximumElements = s.value("NbrMaxDisregardedValues",5).toUInt();
182  _nbrDisregardedMinimumElements = s.value("NbrMinDisregardedValues",0).toUInt();
183  _minNbrPixels = s.value("MinNbrPixels",8).toUInt();
184  s.endGroup();
185 }
void createPixelList(size_t nbrPixels, Detector::frame_t::const_iterator pixel, Detector::frame_t::const_iterator offset, Detector::frame_t::const_iterator noise, CommonData::mask_t::const_iterator mask, float multiplier, Detector::pixel_t initialLevel, pixels_t &pixels)
build up the list of pixels that contribute to the common mode calculation
Settings for CASS.
Definition: cass_settings.h:30
STL namespace.
Detector::pixel_t operator()(Detector::frame_t::const_iterator pixel, size_t idx) const
the operation
void loadSettings(CASSSettings &s)
load the settings of this calculator
void loadSettings(CASSSettings &s)
load the settings of this calculator
float pixel_t
define a pixel of the pixel detector
std::vector< Detector::pixel_t > pixels_t
Detector::pixel_t operator()(Detector::frame_t::const_iterator pixel, size_t idx) const
the operation
value(const QString &key, const QVariant &defaultValue=QVariant()
noise and mask[Processor]
void loadSettings(CASSSettings &s)
load the settings of this calculator
contains the common data for one advanced pixeldetector
file contains specialized class that do the settings for cass
contains all available common mode calculators.
offset
int16_t pixel
define a pixel
Definition: hlltypes.hpp:27
Detector::pixel_t operator()(Detector::frame_t::const_iterator pixel, size_t idx) const
the operation
beginGroup(const QString &prefix)
set up how to create the noise