added function for automatic detection of threshold for dark count trigger