9 #include <boost/format.hpp> 23 event_time_(event_time),
27 max_cell_gap_cut_ = 20;
28 track_max_beta_ = 5
e-3;
29 track_min_beta_ = 4
e-5;
30 trigger_time_buffer_ = 256;
36 parameter_[
"algorithm_time"] = duration_cast<milliseconds>(
t1-
t0).
count();
39 << duration_cast<milliseconds>(
t1-
t0).
count() <<
" ms" 45 std::vector<novaddt::TriggerDecision>
48 return trigger_decisions_;
55 return trigger_time_buffer_;
61 std::map<std::string, novaddt::HitList>
64 return essential_hit_lists_;
71 if (parameter_.find(name) == parameter_.end())
81 if (parameter_.find(name) == parameter_.end())
83 std::cerr <<
"\n\tParameter " << name <<
" is not available.\n" 88 return parameter_[
name];
106 std::map<std::string, novaddt::HitList> hitmap;
107 split_by_view(hits_, hitmap);
120 hitmap[
"x_contained"];
122 find_view_matched_hits(hitmap);
140 unsigned n_good_track = 0;
141 for (
auto entry_hit = hitmap[
"x_surface"].cbegin();
142 entry_hit != hitmap[
"x_surface"].cend() && !
result;
146 novaddt::HitList::const_reverse_iterator until(entry_hit + 1);
148 auto contained_first = find(hitmap[
"x_contained"], entry_hit->TDC());
153 auto contained_last =
154 find(contained_first, hitmap[
"x_contained"].cend(), exit_hit.
TDC());
169 if (!good_track(track))
172 if (++n_good_track % sparsification_factor_)
175 std::set<int> plane_set = {entry_hit->Plane().val};
176 std::set<int> cell_set = {entry_hit->Cell().val};
185 unsigned long long t_max_gap =
std::min(t_max_plane_gap, t_max_cell_gap);
187 unsigned n_contained_hit = 0;
188 bool contains_gap_exceeding_cut = std::any_of
189 (contained_first, contained_last,
192 if (hit.
TDC().
val > t_max_gap)
194 int64_t time_difference =
195 static_cast<int64_t
>(hit.
TDC().
val) -
198 if (hit.
TDC().
val > t_max_cell_gap)
200 double expected_cell =
205 if (gap_exceeds_cut(cell_set, expected_cell, max_cell_gap_cut_))
209 if (hit.
TDC().
val > t_max_plane_gap)
211 double expected_plane =
217 (plane_set, expected_plane, max_plane_gap_cut_))
222 if (hit_is_in_time_with_road(hit, track))
224 cell_set.insert(hit.
Cell().
val);
235 if (contains_gap_exceeding_cut)
242 plane_set.insert(exit_hit.
Plane().
val);
251 if (find_max_gap(plane_set) > max_plane_gap_cut_)
254 cell_set.insert(exit_hit.
Cell().
val);
260 if (find_max_gap(cell_set) > max_cell_gap_cut_)
264 trigger_entry_hit = *entry_hit;
265 trigger_exit_hit = exit_hit;
270 std::cout <<
"MF: Trigger Decision Track:" 271 <<
"\nMF: (distance, velocity) = (" 286 auto t0 = trigger_entry_hit.
TDC().
val;
290 emplace_back(
t0 - 2 * trigger_time_buffer_,
291 dt + 4 * trigger_time_buffer_,
294 essential_hit_lists_[
"mf_entry_exit"].push_back(trigger_entry_hit);
295 essential_hit_lists_[
"mf_entry_exit"].push_back(trigger_exit_hit);
305 std::map<std::string, novaddt::HitList> & hitmap)
const 307 auto bound = std::stable_partition
308 (hits.begin(), hits.end(),
313 std::move(hits.begin(), bound, hitmap[
"x"].begin());
316 std::move(bound, hits.end(), hitmap[
"y"].begin());
322 (std::map<std::string, novaddt::HitList> & hitmap)
const 324 for (
auto const& x_hit : hitmap[
"x"])
336 return hits_are_view_matched(x_hit, y_hit);
339 if (y_match != y_last)
342 hitmap[
"x_contained"].push_back(x_hit);
345 if (hit_is_on_surface(x_hit))
347 hitmap[
"x_surface"].push_back(x_hit);
354 if (!hits_are_view_matched(x_hit, y_hit))
357 if (!hit_is_on_surface(y_hit))
363 if (surface_y_match != y_last)
364 hitmap[
"x_surface"].push_back(x_hit);
375 int plane_difference =
412 if (track.
velocity() < track_min_beta_)
415 if (track.
velocity() > track_max_beta_)
431 if (!hit_is_between_track_end_points(hit, track))
440 (
static_cast<double>(hit.
Plane().
val) -
460 if (!hit_is_on_road(hit, track))
469 int64_t relative_hit_time =
470 static_cast<int64_t
>(hit.
TDC().
val) -
474 (
static_cast<double>(hit.
Plane().
val) -
477 if (relative_hit_time >
481 if (relative_hit_time <
491 (std::set<int> collection,
int const&
object,
int const& max_gap_cut)
const 495 collection.insert(
object);
508 if (find_max_gap(collection) > max_gap_cut)
517 (std::set<int>
const& collection)
const 522 (collection.begin(), collection.end(), [&](
int object,
int next_object)
524 int gap = next_object - object;
559 (novaddt::HitList::const_iterator begin,
562 return std::lower_bound(begin, end, tdc,
571 return find(hits.cbegin(), hits.cend(), tdc);
T max(const caf::Proxy< T > &a, T b)
const unsigned ROAD_HALF_WIDTH
bool hit_is_in_time_with_road(novaddt::DAQHit const &hit, Track const &track) const
bool hits_are_view_matched(novaddt::DAQHit const &x_hit, novaddt::DAQHit const &y_hit) const
int plane_difference() const
bool slope_plane_is_valid() const
unsigned max_plane() const
novaddt::DAQHit start_ddt() const
std::vector< novaddt::TriggerDecision > trigger_decisions() const
SlowMonopoleTrigger(novaddt::HitList const &h, unsigned long long const &event_time, Configuration const &c)
novaddt::Plane const & Plane() const
novaddt::TDC const & TDC() const
std::vector< DAQHit > HitList
bool hit_is_on_surface(novaddt::DAQHit const &hit) const
void find_view_matched_hits(std::map< std::string, novaddt::HitList > &hitmap) const
const unsigned SURFACE_MAX_CELL
bool parameter_exists(std::string const name) const
unsigned distance(const T &t1, const T &t2)
bool slope_time_is_valid() const
const unsigned SURFACE_MAX_PLANE
std::map< std::string, novaddt::HitList > essential_hit_lists() const
const double ROAD_TIME_VARIATION
novaddt::HitList::const_iterator find(novaddt::HitList::const_iterator begin, novaddt::HitList::const_iterator end, novaddt::TDC tdc) const
double slope_plane_time() const
int find_max_gap(std::set< int > const &collection) const
unsigned max_cell() const
bool good_track(Track const &track) const
void print(novaddt::DAQHit const &h, unsigned long long const &event_time=0)
unsigned trigger_decision_time_buffer() const
Identifier for the X measuring view of the detector (top)
const unsigned TRACK_MIN_UNIQUE_PLANES
const unsigned VIEW_MATCH_PLANE_CUT
const unsigned SURFACE_MIN_PLANE
const double TRACK_MIN_DISTANCE
bool hit_is_on_road(novaddt::DAQHit const &hit, Track const &track) const
bool slope_cell_is_valid() const
void split_by_view(novaddt::HitList hits, std::map< std::string, novaddt::HitList > &hitmap) const
double parameter(std::string const name)
double slope_cell_plane() const
double slope_time_plane() const
bool gap_exceeds_cut(std::set< int > collection, int const &object, int const &max_gap_cut) const
unsigned sparsification_factor
double slope_time_cell() const
novaddt::Cell const & Cell() const
assert(nhit_max >=nhit_nbins)
bool hit_is_between_track_end_points(novaddt::DAQHit const &hit, Track const &track) const
unsigned min_cell() const
T min(const caf::Proxy< T > &a, T b)
const unsigned SURFACE_MIN_CELL
const unsigned VIEW_MATCH_TDC_CUT
double slope_cell_time() const
const unsigned TRACK_MIN_HITS
unsigned min_plane() const