Skip to content

Commit

Permalink
"time cutoffs for correlated TOFs; updates #213"
Browse files Browse the repository at this point in the history
  • Loading branch information
martukas committed May 8, 2019
1 parent 88f646c commit b1d42fe
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 18 deletions.
30 changes: 21 additions & 9 deletions source/consumers/tof_1d_correlate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
}
Expand All @@ -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();

Expand Down Expand Up @@ -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<size_t>(nsecs * time_resolution_);

if (coords_[0] >= domain_.size())
Expand Down
1 change: 1 addition & 0 deletions source/consumers/tof_1d_correlate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;

Expand Down
31 changes: 22 additions & 9 deletions source/consumers/tof_val_2d_correlate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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"));

Expand All @@ -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();
Expand Down Expand Up @@ -161,6 +171,9 @@ bool TOFVal2DCorrelate::bin_events()
if (nsecs < 0.)
continue;

if ((time_cutoff_ > 0.) && (nsecs > time_cutoff_))
continue;

coords_[0] = static_cast<size_t>(nsecs * time_resolution_);

value_latch_.extract(coords_[1], event);
Expand Down
1 change: 1 addition & 0 deletions source/consumers/tof_val_2d_correlate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down

0 comments on commit b1d42fe

Please sign in to comment.