# HOW-TO Derive the gain¶

## Definition¶

The gain is the conversion factor between the signal in ADU’s supplied by the readout electronics and the detected number of photons (in units e$$^{-}$$/ADU). The gain factors are needed to convert ADU’s in raw bias-corrected frames to the number of electrons, i.e. detected photons. For OmegaCAM a procedure (template) to determine the gain is defined, which involves taking two series of 10 dome flatfield exposures with a wide range of exposure times. Derive the rms of the differences of two exposures taken with similar exposure (integration time). Exposure differences of pairs should not exceed 4%. The regression of the square of these values with the median level yields the conversion factor in e$$^{-}$$/ADU (assuming noise dominated by photon shot noise).

## Deriving the gain¶

For most instruments default gain values have been determined and are in the system, so it is usually not necessary to make your own values. The class used to store the gain in the database is called GainLinearity. Existing gain values can be obtained for example with this query from the awe prompt (fill in the appropriate instrument, observing date and chip):

awe> q = (GainLinearity.instrument.name == 'OMEGACAM') & \
(GainLinearity.template.start > datetime.datetime(2014,7,2)) & \
(GainLinearity.template.start < datetime.datetime(2014,7,4))
awe> print(q[0].template.start, q[0].gain)
2014-07-03 12:35:56 2.49576806277451


There is a recipe to use the 20 domeflats to determine the gain. The recipe can be used like this:

awe> task = GainTask(instrument='OMEGACAM', template='2014-07-03 12:35:56',
chip='ESO_CCD_#65')