otsdaq-mu2e-stm  5.02.01
mwd_config.hh
1 #ifndef MWD_CONFIG_HH_
2 #define MWD_CONFIG_HH_
3 
4 // Include config files
5 #include "Mu2e-STMDAQ/config/config.hh"
6 #include "Mu2e-STMDAQ/config/include/fw_config.hh"
7 
8 // Zero suppression configurable variables
9 struct mwd_info{
10 
11  // Baseline subtraction
12  const bool use_manual_baseline; // Use manual value?
13  const double manual_mean, manual_sigma; // Manual (user config) mean and sigma
14  const bool use_window_baseline; // If not manual, use dynamic sliding window baseline?
15 
16  // Deconvolution
17  const double tau, tau_norm; // HPGe decay time constant (us)
18 
20  const int M; // M value (must be power of 2)
21  const size_t m_mask; // M-1
22 
23  // Averaging
24  const int L; // L value (must be power of 2)
25  const double inv_L; // 1/L
26  const size_t l_mask; // L-1
27 
28  // Peak finding
29  const double peak_min_init; // The initial minimum value for the peak
30  const bool use_fixed_cut; // Use fixed peak finding threshold cut?
31  const double fixed_cut_value; // Fixed cut value
32  const double nsigma_cut; // Dynamic cut: number of sigma below baseline
33 
34  // Constructor
35  mwd_info(Config& cfg, const std::shared_ptr<AsyncLogger> logger,
36  fw_info fw_config,
37  baseline_info baseline_config) :
38  // Baseline subtraction
39  use_manual_baseline(cfg.getValue<int>("stm.mwd.baseline.use_manual_value")),
40  manual_mean(cfg.getValue<double>("stm.mwd.baseline.manual_value.mean")),
41  manual_sigma(cfg.getValue<double>("stm.mwd.baseline.manual_value.sigma")),
42  use_window_baseline(cfg.getValue<int>("stm.mwd.baseline.use_window_value")),
43  // Deconvolution
44  tau(cfg.getValue<double>("stm.mwd.deconv.hpge_tau")), // Decay constant (us)
45  tau_norm(1.0-fw_config.tADC/tau),
46  // Differentiation
47  M(cfg.getValue<int>("stm.mwd.diff.M")), // M value
48  m_mask(M-1), // M-1
49  // Averaging
50  L(cfg.getValue<int>("stm.mwd.avg.L")), // L value
51  inv_L(1.0/static_cast<double>(L)), // Reciprocal of L
52  l_mask(L-1), // L-1
53  // Peak finding
54  peak_min_init(cfg.getValue<double>("stm.mwd.peak_finding.peak_min_init")), // minimum peak value
55  use_fixed_cut(cfg.getValue<int>("stm.mwd.peak_finding.use_fixed_cut")), // Fixed cut?
56  fixed_cut_value(cfg.getValue<double>("stm.mwd.peak_finding.fixed_cut_value")), // Fixed value
57  nsigma_cut(cfg.getValue<double>("stm.mwd.peak_finding.nsigma_cut")) // Dynamic sigma cut
58  {
59  if (logger){
60  // Check that M value is a power of 2
61  if ((M & (M - 1)) != 0) {
62  logger->log("Config:mwd_info: Error! M must be a power of 2! M = "
63  + std::to_string(M) + " in " + cfg.getXMLpath() + ".",0);
64  }
65 
66  // Check that L value is a power of 2
67  if ((L & (L - 1)) != 0) {
68  logger->log("Config:mwd_info: Error! L must be a power of 2! L = "
69  + std::to_string(L) + " in " + cfg.getXMLpath() + ".",0);
70  }
71 
72  // Check whether baseline operations are on
73  const bool ops_baseline_class =
74  cfg.getValue<int>("stm.operations.Baseline");
75  const bool ops_baseline_func =
76  cfg.getValue<int>("stm.operations.Baseline.calc_baseline");
77 
78  // Check any of the conditions requiring fallback to manual baseline
79  if (!ops_baseline_class || !ops_baseline_func){
80  std::string msg =
81  "Config:mwd_info: Baseline operations disabled in config. Forcing use of manual (user) baseline.";
82  logger->log(msg, 2);
83  // Force manual baseline
84  const_cast<bool&>(use_manual_baseline) = true;
85  }
86 
87  // Notify user
88  if (use_manual_baseline){ // If using manual baseline value
89  logger->log("Config:mwd_info: Using manual (user) baseline value of " +
90  std::to_string(manual_mean) +
91  " ± " + std::to_string(manual_sigma) +
92  " ADCs for baseline subtraction and pulse height calculation.",1);
93  }
94  // If if not manual baseline
95  else{
96  if (use_window_baseline){ // If using sliding window
97  logger->log("Config:mwd_info: Using " +
98  std::to_string(baseline_config.hist_window_period) +
99  " second sliding window baseline for baseline subtraction "
100  "and pulse height calculation.", 1);
101  }
102  else{ // Else use baseline value calculated since start of run
103  logger->log("Config:mwd_info: Using baseline calculated continuosly since "
104  "start of run for baseline subtraction "
105  "and pulse height calculation.", 1);
106  }
107  }
108 
109  logger->log("Config:mwd_info HPGe decay time constant [tau] = "
110  + std::to_string(tau)
111  + " us: 1 - tADC/tau = "
112  + std::to_string(tau_norm) + ".",1);
113  logger->log("Config:mwd_info M/L values = " + std::to_string(M)
114  + "/" + std::to_string(L) + ".",1);
115  logger->log("Config:mwd_info Initial minimum value for peak = "
116  + std::to_string(peak_min_init) + ".",1);
117  std::string fixed_cut = (use_fixed_cut) ? "TRUE" : "FALSE";
118  logger->log("Config:mwd_info Using fixed peak finding threshold cut = " + fixed_cut + ".",1);
119  if (use_fixed_cut){
120  logger->log("Config:mwd_info Fixed peak finding threshold cut value = "
121  + std::to_string(fixed_cut_value) + ".",1);
122  }
123  else{
124  logger->log("Config:mwd_info Calculating peak finding cut value as "
125  + std::to_string(nsigma_cut) + " sigmas away from baseline mean.",1);
126  }
127  }
128  }
129 
130 };
131 
132 #endif
Definition: config.hh:19
const int M
Differentiation.
Definition: mwd_config.hh:20