CFEL - ASG Software Suite  2.5.0
CASS
mapcreators.h
Go to the documentation of this file.
1 // Copyright (C) 2011 Lutz Foucar
2 
3 /**
4  * @file mapcreators.h contains all correction map creators.
5  *
6  * @author Lutz Foucar
7  */
8 
9 #ifndef _MAPCREATORS_H_
10 #define _MAPCREATORS_H_
11 
12 #include <tr1/memory>
13 #include <tr1/functional>
14 #include <vector>
15 
16 #include "mapcreator_base.h"
17 
18 namespace cass
19 {
20 class CASSSettings;
21 
22 namespace pixeldetector
23 {
24 //forward declaration//
25 struct Frame;
26 class CommonData;
27 
28 
29 /** Creates maps from a fixed number of Frames
30  *
31  * Creates the maps after collecting a user given number of frames. The maps will
32  * be created using standart statistics. The user has the choice of whehter the
33  * mean or the median should be used for the offset value.
34  *
35  * @MapCreateList "fixed": The maps will be created from a fixed number of frames.
36  *
37  * @cassttng PixelDetectors/\%name\%/CorrectionMaps/FixedCreator/{NbrFrames}\n
38  * The number of frames that should be collected for calculating the
39  * maps. Default is 200.
40  * @cassttng PixelDetectors/\%name\%/CorrectionMaps/FixedCreator/{StartInstantly}\n
41  * Flag to tell whether the calculator should start instantly with
42  * collecting the frames and calculating the maps. If false it will
43  * wait until told by the program through the available GUI's. Default
44  * is false.
45  * @cassttng PixelDetectors/\%name\%/CorrectionMaps/FixedCreator/{DisregardedHighValues}\n
46  * Number of highest values that should be disregarded when calculating
47  * the offset value. Default is 5
48  * @cassttng PixelDetectors/\%name\%/CorrectionMaps/FixedCreator/{DisregardedLowValues}\n
49  * Number of lowest values that should be disregarded when calculating
50  * the offset value. Default is 0
51  * @cassttng PixelDetectors/\%name\%/CorrectionMaps/FixedCreator/{UseMedian}\n
52  * Tell the creator to use a median to calculate the offset value.
53  * If this is false the offset is calculated via the mean value.
54  * Default is false
55  * @cassttng PixelDetectors/\%name\%/CorrectionMaps/FixedCreator/{WriteMaps}\n
56  * Tell the creator to write the calulated maps once they have been
57  * calculated. For further infomration on how the files are written,
58  * see cass::pixeldetector::CommonData. Default is true.
59  *
60  * @author Lutz Foucar
61  */
62 class FixedMaps : public MapCreatorBase
63 {
64 public:
65  /** build map from frame
66  *
67  * take the input frame and use its data to build up the correction maps. But
68  * only when the _createMaps flag is set to true.
69  *
70  * Once the _storage container is full calculate the maps. First retrieve for
71  * each pixel a list of all pixels within the storage that don't contain an
72  * event (e.g. photonhit).
73  *
74  * The map resources are locked since the function calling this operator will
75  * lock the resources.
76  *
77  * After calculation reset the _createMaps flag and clear the storage.
78  *
79  * @param frame the frame containing the data to build the maps from
80  */
81  void operator() (const Frame &frame);
82 
83  /** load the settings of this creator
84  *
85  * See class description for a detailed list.
86  *
87  * @param s the CASSSettings object to read the information from
88  */
89  void loadSettings(CASSSettings &s);
90 
91  /** start accumulating the maps */
92  void controlCalibration(const std::string& /*unused*/) {_createMaps = true;}
93 
94 private:
95  /** the container with all the maps */
96  std::tr1::shared_ptr<CommonData> _commondata;
97 
98  /** the function that will calculate the offset */
99  std::tr1::function<Detector::frame_t::value_type(Detector::frame_t&, size_t, size_t)> _calcOffset;
100 
101  /** the storage with all the frames from which the maps are calculated */
103 
104  /** flag to tell whether the maps should be created */
106 
107  /** how many frames should be included to create the statistics */
108  size_t _nbrFrames;
109 
110  /** how many highest values should be disregarded */
112 
113  /** how many lowest values should be disregarded */
115 
116  /** write maps flag */
118 };
119 
120 
121 /** Creates maps from the last number of maps
122  *
123  * The algorithm that calculates the running average (offset) and standard
124  * deviation is taken from here (last checked 30.01.2012):
125  * http://www-uxsup.csx.cam.ac.uk/~fanf2/hermes/doc/antiforgery/stats.pdf
126  *
127  * @MapCreateList "moving": The maps will be created from the last few frames.
128  *
129  * @cassttng PixelDetectors/\%name\%/CorrectionMaps/ChangingCreator/{NbrTrainingFrames}\n
130  * The number of frames that should be collected for calculating the
131  * initial maps. Default is 50.
132  * @cassttng PixelDetectors/\%name\%/CorrectionMaps/ChangingCreator/{DoTraining}\n
133  * Before updating collect a set of "training" frames from which the
134  * initial maps are created. This is recommended if one does not have
135  * or has an outdated noise and offset map. Default is false.
136  * @cassttng PixelDetectors/\%name\%/CorrectionMaps/ChangingCreator/{NbrOfAverages}\n
137  * The number of past frames that should be taken into account when
138  * calculating the noise and offset map. Default is 50.
139  * @cassttng PixelDetectors/\%name\%/CorrectionMaps/ChangingCreator/{Multiplier}\n
140  * How much bigger does the pixel value have to be than the noise before
141  * The pixel is not taken into account when calculating the offset and
142  * noise of that pixel. Default is 4.
143  * @cassttng PixelDetectors/\%name\%/CorrectionMaps/ChangingCreator/{AutoSaveSize}\n
144  * Tells to save the noise and offset map and recalculate the correction
145  * map after this many frames. Default is 1e6.
146  *
147  * @author Lutz Foucar
148  */
150 {
151 public:
152  /** build map from frame
153  *
154  * The map resources are locked since the function calling this operator will
155  * lock the resources.
156  *
157  * take the input frame and use its data to build up the correction maps.
158  *
159  * @param frame the frame containing the data to build the maps from
160  */
161  void operator() (const Frame &frame) {_createMap(frame);}
162 
163  /** load the settings of this creator
164  *
165  * @param s the CASSSettings object to read the information from
166  */
167  void loadSettings(CASSSettings &s);
168 
169  /** start the training
170  *
171  * @param unused (not used)
172  */
173  void controlCalibration(const std::string& unused);
174 
175 private:
176  /** train the maps
177  *
178  * collect user settable amount of frames and create intial maps from it
179  * these maps will then be updated with each new frame
180  *
181  * @param frame the frame to build up the storage and to calc the maps from
182  */
183  void train(const Frame &frame);
184 
185  /** update the existing map with the incomming frame inforamtion
186  *
187  * will update the maps with the information of the frame
188  *
189  * @param frame the frame to update the maps from
190  */
191  void updateMaps(const Frame &frame);
192 
193 private:
194  /** the container with all the maps */
195  std::tr1::shared_ptr<CommonData> _commondata;
196 
197  /** the function object that will be called by the operator */
198  std::tr1::function<void(const Frame&)> _createMap;
199 
200  /** the storage with all the frames from which the maps are calculated */
202 
203  /** counter to keep track how many frames are collected */
205 
206  /** after wich number of frames should the maps be written to file */
207  size_t _frameSave;
208 
209  /** how much frames should the training include */
211 
212  /** how many frames should the memory go back */
213  float _alpha;
214 
215  /** how much noise is allowed before disregarding pixel from list */
216  float _multiplier;
217 };
218 
219 
220 /** hotpixels finder
221  *
222  * @MapCreateList "hotpix": Pixels that have a high value for a consecutive nbr
223  * of frames will be identified.
224  *
225  * @cassttng PixelDetectors/\%name\%/CorrectionMaps/HotPixelFinder/{ADUThreshold}\n
226  * @cassttng PixelDetectors/\%name\%/CorrectionMaps/HotPixelFinder/{NbrConsecutiveFrames}\n
227  *
228  * @author Lutz Foucar
229  */
231 {
232 public:
233  /** build map from frame
234  *
235  * @param frame the frame containing the data to build the maps from
236  */
237  void operator() (const Frame &frame);
238 
239  /** load the settings of this creator
240  *
241  * @param s the CASSSettings object to read the information from
242  */
243  void loadSettings(CASSSettings &s);
244 
245 private:
246  /** the container with all the maps */
247  std::tr1::shared_ptr<CommonData> _commondata;
248 
249  /** after wich number of frames should the maps be written to file */
250  size_t _frameSave;
251 
252  /** the adu threshold for identifying a potential hotpixel */
254 
255  /** the nbr of consecutive frames that a hotpixel is high */
257 };
258 
259 } //end namespace pixeldetector
260 } //end namespace cass
261 #endif
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
std::tr1::function< Detector::frame_t::value_type(Detector::frame_t &, size_t, size_t)> _calcOffset
the function that will calculate the offset
Definition: mapcreators.h:99
void train(const Frame &frame)
train the maps
void loadSettings(CASSSettings &s)
load the settings of this creator
Settings for CASS.
Definition: cass_settings.h:30
bool _createMaps
flag to tell whether the maps should be created
Definition: mapcreators.h:105
contains base class for all correction map creators.
void controlCalibration(const std::string &unused)
start the training
bool _writeMaps
write maps flag
Definition: mapcreators.h:117
std::tr1::shared_ptr< CommonData > _commondata
the container with all the maps
Definition: mapcreators.h:247
Detector::pixel_t _aduThreshold
the adu threshold for identifying a potential hotpixel
Definition: mapcreators.h:253
float pixel_t
define a pixel of the pixel detector
void loadSettings(CASSSettings &s)
load the settings of this creator
storage_t _storage
the storage with all the frames from which the maps are calculated
Definition: mapcreators.h:102
size_t _trainingsize
how much frames should the training include
Definition: mapcreators.h:210
void operator()(const Frame &frame)
build map from frame
Creates maps from a fixed number of Frames.
Definition: mapcreators.h:62
char _hotpixThreshold
the nbr of consecutive frames that a hotpixel is high
Definition: mapcreators.h:256
storage_t _storage
the storage with all the frames from which the maps are calculated
Definition: mapcreators.h:201
std::tr1::function< void(const Frame &)> _createMap
the function object that will be called by the operator
Definition: mapcreators.h:198
float _alpha
how many frames should the memory go back
Definition: mapcreators.h:213
size_t _frameSave
after wich number of frames should the maps be written to file
Definition: mapcreators.h:250
size_t _minDisregarded
how many lowest values should be disregarded
Definition: mapcreators.h:114
std::tr1::shared_ptr< CommonData > _commondata
the container with all the maps
Definition: mapcreators.h:195
std::tr1::shared_ptr< CommonData > _commondata
the container with all the maps
Definition: mapcreators.h:96
size_t _framecounter
counter to keep track how many frames are collected
Definition: mapcreators.h:204
A Frame of an advance Pixel Detector.
void controlCalibration(const std::string &)
start accumulating the maps
Definition: mapcreators.h:92
float _multiplier
how much noise is allowed before disregarding pixel from list
Definition: mapcreators.h:216
size_t _maxDisregarded
how many highest values should be disregarded
Definition: mapcreators.h:111
Creates maps from the last number of maps.
Definition: mapcreators.h:149
size_t _nbrFrames
how many frames should be included to create the statistics
Definition: mapcreators.h:108
void updateMaps(const Frame &frame)
update the existing map with the incomming frame inforamtion
base class for all correction map creators
void operator()(const Frame &frame)
build map from frame
Definition: mapcreators.h:161
size_t _frameSave
after wich number of frames should the maps be written to file
Definition: mapcreators.h:207