diff --git a/source/consumers/tof_1d_correlate.cpp b/source/consumers/tof_1d_correlate.cpp index 09f663fa..5776c28f 100644 --- a/source/consumers/tof_1d_correlate.cpp +++ b/source/consumers/tof_1d_correlate.cpp @@ -17,11 +17,10 @@ TOF1DCorrelate::TOF1DCorrelate() app.set_flag("color"); base_options.branches.add(Setting(app)); - SettingMeta res("time_resolution", SettingType::floating, "Time resolution"); - res.set_flag("preset"); - res.set_val("min", 1); - res.set_val("units", "units (see below)"); - base_options.branches.add(res); + SettingMeta stream("chopper_stream_id", SettingType::text, "Chopper stream ID"); + stream.set_flag("preset"); + stream.set_flag("stream"); + base_options.branches.add(stream); SettingMeta units("time_units", SettingType::menu, "Time units (domain)"); units.set_flag("preset"); @@ -31,10 +30,16 @@ TOF1DCorrelate::TOF1DCorrelate() units.set_enum(9, "s"); base_options.branches.add(units); - SettingMeta stream("chopper_stream_id", SettingType::text, "Chopper stream ID"); - stream.set_flag("preset"); - stream.set_flag("stream"); - base_options.branches.add(stream); + SettingMeta res("time_resolution", SettingType::floating, "Time resolution"); + res.set_flag("preset"); + res.set_val("min", 1); + res.set_val("units", "units (see above)"); + base_options.branches.add(res); + + SettingMeta tcutoff("time_cutoff", SettingType::floating, "Max time cutoff (if !=0)"); + tcutoff.set_val("min", 0); + tcutoff.set_val("units", "units (see above)"); + base_options.branches.add(tcutoff); metadata_.overwrite_all_attributes(base_options); } @@ -46,10 +51,14 @@ void TOF1DCorrelate::_apply_attributes() time_resolution_ = 0; if (metadata_.get_attribute("time_resolution").get_number() > 0) time_resolution_ = 1.0 / metadata_.get_attribute("time_resolution").get_number(); + + time_cutoff_ = metadata_.get_attribute("time_cutoff").get_number(); + auto unit = metadata_.get_attribute("time_units").selection(); units_name_ = metadata_.get_attribute("time_units").metadata().enum_name(unit); units_multiplier_ = std::pow(10, unit); time_resolution_ /= units_multiplier_; + time_cutoff_ *= units_multiplier_; chopper_stream_id_ = metadata_.get_attribute("chopper_stream_id").get_text(); @@ -142,6 +151,9 @@ bool TOF1DCorrelate::bin_events() if (nsecs < 0.0) continue; + if ((time_cutoff_ > 0.) && (nsecs > time_cutoff_)) + continue; + coords_[0] = static_cast(nsecs * time_resolution_); if (coords_[0] >= domain_.size()) diff --git a/source/consumers/tof_1d_correlate.h b/source/consumers/tof_1d_correlate.h index c14d51db..cc731874 100644 --- a/source/consumers/tof_1d_correlate.h +++ b/source/consumers/tof_1d_correlate.h @@ -29,6 +29,7 @@ class TOF1DCorrelate : public Spectrum double time_resolution_{1}; std::string units_name_; double units_multiplier_{1}; + double time_cutoff_{0}; std::string chopper_stream_id_; diff --git a/source/consumers/tof_val_2d_correlate.cpp b/source/consumers/tof_val_2d_correlate.cpp index 29ac26a8..a81893ad 100644 --- a/source/consumers/tof_val_2d_correlate.cpp +++ b/source/consumers/tof_val_2d_correlate.cpp @@ -20,11 +20,10 @@ TOFVal2DCorrelate::TOFVal2DCorrelate() SettingMeta flip("flip-y", SettingType::boolean, "Flip Y axis"); base_options.branches.add(flip); - SettingMeta res("time_resolution", SettingType::floating, "Time resolution"); - res.set_flag("preset"); - res.set_val("min", 1); - res.set_val("units", "units (see below)"); - base_options.branches.add(res); + SettingMeta stream("chopper_stream_id", SettingType::text, "Chopper stream ID"); + stream.set_flag("preset"); + stream.set_flag("stream"); + base_options.branches.add(stream); SettingMeta units("time_units", SettingType::menu, "Time units (domain)"); units.set_flag("preset"); @@ -34,10 +33,17 @@ TOFVal2DCorrelate::TOFVal2DCorrelate() units.set_enum(9, "s"); base_options.branches.add(units); - SettingMeta stream("chopper_stream_id", SettingType::text, "Chopper stream ID"); - stream.set_flag("preset"); - stream.set_flag("stream"); - base_options.branches.add(stream); + SettingMeta res("time_resolution", SettingType::floating, "Time resolution"); + res.set_flag("preset"); + res.set_val("min", 1); + res.set_val("units", "units (see above)"); + base_options.branches.add(res); + + SettingMeta tcutoff("time_cutoff", SettingType::floating, "Max time cutoff (if !=0)"); + tcutoff.set_val("min", 0); + tcutoff.set_val("units", "units (see above)"); + base_options.branches.add(tcutoff); + base_options.branches.add(value_latch_.settings(-1, "Value to bin")); @@ -52,9 +58,13 @@ void TOFVal2DCorrelate::_apply_attributes() if (metadata_.get_attribute("time_resolution").get_number() > 0) time_resolution_ = 1.0 / metadata_.get_attribute("time_resolution").get_number(); auto unit = metadata_.get_attribute("time_units").selection(); + + time_cutoff_ = metadata_.get_attribute("time_cutoff").get_number(); + units_name_ = metadata_.get_attribute("time_units").metadata().enum_name(unit); units_multiplier_ = std::pow(10, unit); time_resolution_ /= units_multiplier_; + time_cutoff_ *= units_multiplier_; value_latch_.settings(metadata_.get_attribute("value_latch")); chopper_stream_id_ = metadata_.get_attribute("chopper_stream_id").get_text(); @@ -161,6 +171,9 @@ bool TOFVal2DCorrelate::bin_events() if (nsecs < 0.) continue; + if ((time_cutoff_ > 0.) && (nsecs > time_cutoff_)) + continue; + coords_[0] = static_cast(nsecs * time_resolution_); value_latch_.extract(coords_[1], event); diff --git a/source/consumers/tof_val_2d_correlate.h b/source/consumers/tof_val_2d_correlate.h index d590d74d..fe99036d 100644 --- a/source/consumers/tof_val_2d_correlate.h +++ b/source/consumers/tof_val_2d_correlate.h @@ -34,6 +34,7 @@ class TOFVal2DCorrelate : public Spectrum double time_resolution_{1}; std::string units_name_; double units_multiplier_{1}; + double time_cutoff_{0}; ValueLatch value_latch_; std::string chopper_stream_id_;