CFEL - ASG Software Suite  2.5.0
CASS
gaincalibration.h
Go to the documentation of this file.
1 // Copyright (C) 2013 Lutz Foucar
2 
3 /**
4  * @file gaincalibration.h contains a gain calibration functor
5  *
6  * @author Lutz Foucar
7  */
8 
9 #ifndef _GAINCALIBRATION_H_
10 #define _GAINCALIBRATION_H_
11 
12 #include <tr1/memory>
13 #include <tr1/functional>
14 #include <vector>
15 
16 #include "mapcreator_base.h"
18 
19 namespace cass
20 {
21 class CASSSettings;
22 
23 namespace pixeldetector
24 {
25 //forward declaration//
26 struct Frame;
27 class CommonData;
28 
29 /** Creates a gain calibration
30  *
31  * Generates the gain map.
32  *
33  * @GainMapCreateList "GainFixedADURange": gain value from the average pixelvalue
34  * within a given ADU range
35  *
36  *
37  * @cassttng PixelDetectors/\%name\%/CorrectionMaps/GainFixedADURange/{StartInstantly}\n
38  * Flag to tell whether the calculator should start instantly after
39  * loading the seetings. If false it will wait until told by the
40  * program through the available GUI's. Default is false.
41  * @cassttng PixelDetectors/\%name\%/CorrectionMaps/GainFixedADURange/{NbrFrames}\n
42  * The number of frames that should be processed before the gain map is calculated.
43  * Default is -1, which means that the only criteria is that the MinimumMedianCounts
44  * have to be reached before calulating the gain map.
45  * @cassttng PixelDetectors/\%name\%/CorrectionMaps/GainFixedADURange/{MinimumPhotonCount}\n
46  * How many times the adu value of the pixel was in the user defined
47  * ADURange, before the gain for this pixel will be calculated. Default
48  * is 50
49  * @cassttng PixelDetectors/\%name\%/CorrectionMaps/GainFixedADURange/{MinimumMedianCounts}\n
50  * The gain values are only calculates when median counts per pixel
51  * exeed this value. Default is 50.
52  * @cassttng PixelDetectors/\%name\%/CorrectionMaps/GainFixedADURange/{MinADURange|MaxADURange}\n
53  * The range in ADU in which the pixelvalue has to lie before it is
54  * taken into the statistics. Default is 0|1000.
55  * @cassttng PixelDetectors/\%name\%/CorrectionMaps/GainFixedADURange/{SaveCalibration}\n
56  * If true writes the gain calibration to file. For further
57  * information on how the files are written, see
58  * cass::pixeldetector::CommonData. Default is true.
59  * @cassttng PixelDetectors/\%name\%/CorrectionMaps/GainFixedADURange/{CommonModeCalculationType}\n
60  * defines what kind of common mode correction should be done with the
61  * frames. There are settings that are used fo all calculation types.
62  * see cass::pixeldetector::commonmode::CalculatorBase. Default type
63  * is "none". Possible values are:
64  * - "none": No common mode correction is done
65  * - "simpleMean": The common mode is calculated from the mean value
66  * Which is determined with a simple algorithm. See
67  * cass::pixeldetector::commonmode::SimpleMeanCalculator
68  * - "mean": The common mode is calculated from the mean value of the
69  * pixels. See cass::pixeldetector::commonmode::MeanCalculator
70  * - "median": The common mode is calculated from the median of the
71  * pixels. See
72  * cass::pixeldetector::commonmode::MedianCalculator for
73  * details.
74  *
75  * @author Lutz Foucar
76  */
78 {
79 public:
80  /** generate gain map from frame
81  *
82  * use the _createMap functor that either does nothing or generates the gain
83  *
84  * @param frame the frame containing the data to build the maps from
85  */
86  void operator() (const Frame &frame) {_createMap(frame);}
87 
88  /** load the settings of this creator
89  *
90  * See class description for a detailed list.
91  *
92  * @param s the CASSSettings object to read the information from
93  */
94  void loadSettings(CASSSettings &s);
95 
96  /** start the gain calibration
97  *
98  * @param unused unused parameter
99  */
100  void controlCalibration(const std::string& unused);
101 
102 private:
103  /** the container with all the maps */
104  std::tr1::shared_ptr<CommonData> _commondata;
105 
106  /** the function object that will be called by the operator */
107  std::tr1::function<void(const Frame&)> _createMap;
108 
109  /** a function that just returns and does nothing
110  *
111  * @param unused not used
112  */
113  void doNothing(const Frame& /*unused*/) {}
114 
115  /** generate gain calibration data
116  *
117  * @param frame the frames that will be added to the calibration
118  */
119  void generateCalibration(const Frame& frame);
120 
121  /** the value that will be set when not enough statistics is present */
122  Detector::frame_t::value_type _constGain;
123 
124  /** define a conatiner for a statistics of a pixel */
125  typedef std::pair<int,double> statistics_t;
126 
127  /** container for the statistics for each pixel */
128  std::vector<statistics_t> _statistics;
129 
130  /** range of ADU values that are of interest */
131  std::pair<Detector::frame_t::value_type,Detector::frame_t::value_type> _range;
132 
133  /** the minimum nbr of photons that the median needs before the gain will calculated */
134  statistics_t::first_type _minMedianCounts;
135 
136  /** minimum nbr of photon seen by a pixel before the average will used */
137  statistics_t::first_type _minPhotonCount;
138 
139  /** flag whether to write the gain calibration to file */
141 
142  /** functor for calculating the common mode level */
144 
145  /** counter to see how many frames have been processed */
146  int64_t _counter;
147 
148  /** how many frames should be processed */
149  int64_t _nFrames;
150 };
151 
152 
153 
154 } //end namespace pixeldetector
155 } //end namespace cass
156 #endif
std::pair< int, double > statistics_t
define a conatiner for a statistics of a pixel
std::tr1::shared_ptr< CalculatorBase > shared_pointer
typedef the shared pointer of this
contains base class for all common mode calculators.
std::vector< statistics_t > _statistics
container for the statistics for each pixel
Settings for CASS.
Definition: cass_settings.h:30
contains base class for all correction map creators.
commonmode::CalculatorBase::shared_pointer _commonModeCalculator
functor for calculating the common mode level
void loadSettings(CASSSettings &s)
load the settings of this creator
statistics_t::first_type _minPhotonCount
minimum nbr of photon seen by a pixel before the average will used
Creates a gain calibration.
std::tr1::shared_ptr< CommonData > _commondata
the container with all the maps
void controlCalibration(const std::string &unused)
start the gain calibration
int64_t _counter
counter to see how many frames have been processed
Detector::frame_t::value_type _constGain
the value that will be set when not enough statistics is present
void operator()(const Frame &frame)
generate gain map from frame
void generateCalibration(const Frame &frame)
generate gain calibration data
void doNothing(const Frame &)
a function that just returns and does nothing
A Frame of an advance Pixel Detector.
std::pair< Detector::frame_t::value_type, Detector::frame_t::value_type > _range
range of ADU values that are of interest
bool _writeFile
flag whether to write the gain calibration to file
base class for all correction map creators
statistics_t::first_type _minMedianCounts
the minimum nbr of photons that the median needs before the gain will calculated
std::tr1::function< void(const Frame &)> _createMap
the function object that will be called by the operator
int64_t _nFrames
how many frames should be processed