25 using tr1::placeholders::_1;
48 const Detector::frame_t::value_type &
noise,
54 MapCreatorBase::storage_t::const_iterator frame(storage.begin());
55 MapCreatorBase::storage_t::const_iterator frameEnd(storage.end());
56 for (; frame != frameEnd ; ++frame)
58 if ((*frame)[
pixel] - offset < noise || !exclude)
59 pixellist.push_back((*frame)[pixel]);
74 transform( zero_mean.begin(), zero_mean.end(),
75 zero_mean.begin(),bind2nd( minus<Detector::frame_t::value_type>(), mean ) );
77 Detector::frame_t::value_type deviation
78 (inner_product( zero_mean.begin(),zero_mean.end(), zero_mean.begin(), 0.0f ));
79 deviation = sqrt( deviation / ( values.size() - 1 ) );
97 sort(values.begin(),values.end());
98 Detector::frame_t::iterator begin(values.begin());
99 Detector::frame_t::iterator end(values.end());
100 advance(begin,mindisregard);
101 advance(end,-1*(maxdisregard));
102 return (accumulate(begin,end,0) / static_cast<Detector::frame_t::value_type>(distance(begin,end)));
122 const int nbrElementsOfInterest
123 (values.size() - mindisregard - maxdisregard);
124 size_t median = 0.5*nbrElementsOfInterest + mindisregard;
125 nth_element(values.begin(),values.begin()+median,values.end());
126 return (values[median]);
141 if (_storage.size() < _nbrFrames)
142 _storage.push_back(frame.
data);
146 Detector::frame_t::iterator
offset(_commondata->offsetMap.begin());
147 Detector::frame_t::iterator offsetEnd(_commondata->offsetMap.end());
148 Detector::frame_t::iterator
noise(_commondata->noiseMap.begin());
153 for (
size_t i=0; i < 2; ++i)
158 *
offset = _calcOffset(pixels,_minDisregarded,_maxDisregarded);
165 _commondata->saveOffsetNoiseMaps();
166 _commondata->createCorMap();
176 _nbrFrames = s.
value(
"NbrFrames",200).toUInt();
177 _maxDisregarded = s.
value(
"DisregardedHighValues",5).toUInt();
178 _minDisregarded = s.
value(
"DisregardedLowValues",0).toUInt();
179 _createMaps = s.
value(
"StartInstantly",
false).toBool();
180 _writeMaps = s.
value(
"WriteMaps",
true).toBool();
181 if(s.
value(
"UseMedian",
false).toBool())
191 Log::add(
Log::INFO,
"MovingMaps::controlCalibration(): start training by collecting '" +
192 toString(_trainingsize) +
"' Frames");
200 if (_framecounter++ < _trainingsize)
202 _storage.push_back(frame.
data);
207 "' frames; building intial offset and noise map");
208 Detector::frame_t::iterator
offset(_commondata->offsetMap.begin());
209 Detector::frame_t::iterator offsetEnd(_commondata->offsetMap.end());
210 Detector::frame_t::iterator
noise(_commondata->noiseMap.begin());
211 storage_t::const_iterator storageBegin(_storage.begin());
212 storage_t::const_iterator storageEnd(_storage.end());
216 size_t accumulatedValues(0);
219 for (storage_t::const_iterator iFrame(storageBegin); iFrame != storageEnd ; ++iFrame)
224 tmp_offset += ((pixel - tmp_offset) / accumulatedValues);
225 tmp_noise += ((pixel - old_offset)*(pixel - tmp_offset));
228 *noise = sqrt(tmp_noise/(accumulatedValues - 1));
230 accumulatedValues = 0;
234 for (storage_t::const_iterator iFrame(storageBegin); iFrame != storageEnd ; ++iFrame)
237 if ((pixel - *
offset < maxNoise))
241 tmp_offset += ((pixel - tmp_offset) / accumulatedValues);
242 tmp_noise += ((pixel - old_offset)*(pixel - tmp_offset));
246 *noise = sqrt(tmp_noise/(accumulatedValues - 1));
248 _commondata->saveOffsetNoiseMaps();
249 _commondata->createCorMap();
258 Detector::frame_t::const_iterator
pixel(frame.
data.begin());
259 Detector::frame_t::const_iterator pixelEnd(frame.
data.end());
260 Detector::frame_t::iterator
offset(_commondata->offsetMap.begin());
261 Detector::frame_t::iterator
noise(_commondata->noiseMap.begin());
270 *offset = *offset + incr;
274 if ((_framecounter % _frameSave) == 0)
276 _commondata->saveOffsetNoiseMaps();
277 _commondata->createCorMap();
287 _trainingsize = s.
value(
"NbrTrainingFrames",50).toUInt();
288 if (s.
value(
"DoTraining",
false).toBool())
291 toString(_trainingsize) +
"' Frames for training.");
296 _frameSave = s.
value(
"AutoSaveSize",1e6).toUInt();
298 _alpha = 2./
static_cast<float>(
average+1.);
299 _multiplier = s.
value(
"Multiplier",4).toFloat();
307 Detector::frame_t::const_iterator
pixel(frame.
data.begin());
308 Detector::frame_t::const_iterator pixelEnd(frame.
data.end());
309 Detector::frame_t::iterator
offset(_commondata->offsetMap.begin());
310 Detector::frame_t::iterator cor(_commondata->correctionMap.begin());
311 CommonData::mask_t::iterator hotpix(_commondata->hotpixels.begin());
312 while(
pixel != pixelEnd)
317 *hotpix = (_aduThreshold < pix)? ++(*hotpix) : 0;
318 if(_hotpixThreshold < *hotpix)
340 _aduThreshold = s.
value(
"ADUThreshold",3000).toFloat();
341 _hotpixThreshold = s.
value(
"NbrConsecutiveFrames",5).toInt();
343 "': Find pixels with adu above '" +
toString(_aduThreshold) +
344 "' When pixel values exeeds threshold for '" +
toString(_hotpixThreshold) +
345 "' consecutive frames its marked as bad.");
void operator()(const Frame &frame)
build map from frame
std::vector< Detector::frame_t > storage_t
the type of storage used
void loadSettings(CASSSettings &s)
load the settings of this creator
determine the particle size by the distance between the first minima of the q average[Processor]
void createPixelList(const Detector::frame_t::value_type &offset, const Detector::frame_t::value_type &noise, const MapCreatorBase::storage_t &storage, size_t pixel, bool exclude, Detector::frame_t &pixellist)
create the list of pixels that are non events
void train(const Frame &frame)
train the maps
void loadSettings(CASSSettings &s)
load the settings of this creator
void controlCalibration(const std::string &unused)
start the training
Detector::frame_t::value_type calcMean(Detector::frame_t &values, size_t mindisregard, size_t maxdisregard)
calculate the mean of the distribution
T square(const T &val)
multiply number by itself
static void add(Level level, const std::string &line)
add a string to the log
float pixel_t
define a pixel of the pixel detector
void loadSettings(CASSSettings &s)
load the settings of this creator
void operator()(const Frame &frame)
build map from frame
contains all correction map creators.
std::vector< pixel_t > frame_t
a frame is a vector of pixels
Detector::frame_t::value_type calcNoise(const Detector::frame_t &values, const Detector::frame_t::value_type &mean)
calulate the standart deviation of distribution
static std::string fromSettings(const CASSSettings &s)
retrieve it from the casssettings
std::string toString(const Type &t)
convert any type to a string
value(const QString &key, const QVariant &defaultValue=QVariant()
A Frame of an advance Pixel Detector.
Detector::frame_t data
the frame data
contains the common data for one advanced pixeldetector
file contains specialized class that do the settings for cass
static shared_pointer instance(const instancesmap_t::key_type &detector)
static function creating instance of this.
void updateMaps(const Frame &frame)
update the existing map with the incomming frame inforamtion
contains a logger for cass
int16_t pixel
define a pixel
beginGroup(const QString &prefix)
Detector::frame_t::value_type calcMedian(Detector::frame_t &values, size_t mindisregard, size_t maxdisregard)
calculate the median of the distribution
set up how to create the noise