active.cxx
Go to the documentation of this file.
1 #include <gtk/gtk.h>
2 #include <math.h>
3 #include <stdlib.h>
4 #include <float.h>
5 #include <stdint.h>
6 #include <vector>
7 #include "event.h"
8 #include "absgeo.h"
9 #include "geo.h"
10 #include "drawing.h"
11 #include "tracks.h"
12 #include "vertices.h"
13 #include "status.h"
14 
15 extern std::vector<noeevent> theevents;
16 extern int gevi;
17 
19 
20 // The positions of all the track points on the screen. We save this
21 // separately from the physical tracks so that we can quickly calculate
22 // which track the user is mousing over. Same idea for vertices.
23 std::vector<screentrack_t> screentracks[kXorY];
24 std::vector<screenvertex_t> screenvertices[kXorY];
25 
27 
28 // How close the mouse pointer should be to a reconstructed object for
29 // it to make that object active.
30 static const int min_pix_to_be_close = 20;
31 
32 // Given a screen position, return the closest vertex. If the position
33 // is nowhere near a vertex, can return -1. If there are no vertices,
34 // returns -1.
36  const int x, const int y)
37 {
38  if(theevents[gevi].vertices.empty()) return -1;
39 
40  int closesti = -1;
41  float mindist = FLT_MAX;
42  for(unsigned int i = 0; i < screenvertices[view].size(); i++){
43  const float dist = hypot(x-screenvertices[view][i].pos.first,
44  y-screenvertices[view][i].pos.second);
45  if(dist < mindist){
46  mindist = dist;
47  closesti = screenvertices[view][i].i; // index into the full vertex array
48  }
49  }
50 
51  if(mindist < min_pix_to_be_close) return closesti;
52  return -1;
53 }
54 
55 
56 // Given a screen position, return the closest track. Preferably the
57 // definition of "closest" matches what a user would expect. If the
58 // position is nowhere near a track, can return -1. If there are no
59 // tracks, returns -1.
61  const int x, const int y)
62 {
63  if(theevents[gevi].tracks.empty()) return -1;
64 
65  int closesti = -1;
66  float mindist = FLT_MAX;
67  for(unsigned int i = 0; i < screentracks[view].size(); i++){
68  const float dist = screen_dist_to_track(x, y, screentracks[view][i].traj);
69  if(dist < mindist){
70  mindist = dist;
71  closesti = screentracks[view][i].i; // index into the full track array
72  }
73  }
74 
75  if(mindist < min_pix_to_be_close) return closesti;
76  return -1;
77 }
78 
79 static bool visible_hit(const int32_t tdc, const int TDCSTEP)
80 {
81  return tdc <= theevents[gevi].current_maxtick &&
82  tdc >= theevents[gevi].current_mintick - (TDCSTEP-1);
83 }
84 
85 // Given a screen position, returns the cell number. If no hit cell is in this
86 // position, return the number of the closest cell in screen y coordinates,
87 // i.e. the closest hit cell that is directly above or below the screen position,
88 // even if the closest one is in another direction. But if this position is
89 // outside the detector boxes on the right or left, return -1.
90 static int screen_to_activecell(noe_view_t view, const int x,
91  const int y, const int TDCSTEP)
92 {
93  const int c = screen_to_cell(view, x, y);
94  const int plane = screen_to_plane(view, x);
95 
96  if(c < 0) return -1;
97  if(c >= ncells_perplane) return -1;
98  if(plane >= first_mucatcher && view == kY && c >= 2*ncells_perplane/3) return -1;
99 
100  std::vector<hit> & THEhits = theevents[gevi].hits;
101  int mindist = 9999, closestcell = -1;
102  for(unsigned int i = 0; i < THEhits.size(); i++){
103  if(THEhits[i].plane != plane) continue;
104  if(!visible_hit(THEhits[i].tdc, TDCSTEP)) continue;
105  const int dist = abs(THEhits[i].cell - c);
106  if(dist < mindist){
107  mindist = dist;
108  closestcell = THEhits[i].cell;
109  }
110  }
111 
112  return closestcell;
113 }
114 
115 void update_active_indices(const noe_view_t V, const int x, const int y,
116  const int TDCSTEP)
117 {
118  active_plane = screen_to_plane (V, x);
119  active_cell = screen_to_activecell (V, x, y, TDCSTEP);
122 }
int active_cell
Definition: main.cxx:78
static int screen_to_activevertex(const noe_view_t view, const int x, const int y)
Definition: active.cxx:35
int active_plane
Definition: main.cxx:78
std::vector< noeevent > theevents
Definition: noe_module.cc:28
int active_vertex
Definition: main.cxx:78
std::enable_if_t< std::is_arithmetic< T >::value, T > hypot(T x, T y)
Definition: hypot.h:60
Supply basic geometry functions.
Definition: geo.h:1
void abs(TH1 *hist)
static int screen_to_activecell(noe_view_t view, const int x, const int y, const int TDCSTEP)
Definition: active.cxx:90
const Var kY([](const caf::SRProxy *sr){float tmp=0.f;if(sr->mc.nu.empty()) return tmp;tmp=sr->mc.nu[0].y;return tmp;})
double dist
Definition: runWimpSim.h:113
int first_mucatcher
Definition: geo.cxx:21
void update_active_indices(const noe_view_t V, const int x, const int y, const int TDCSTEP)
Definition: active.cxx:115
static int TDCSTEP
Definition: main.cxx:72
static int screen_to_activetrack(const noe_view_t view, const int x, const int y)
Definition: active.cxx:60
static const int min_pix_to_be_close
Definition: active.cxx:30
float screen_dist_to_track(const int x, const int y, const std::vector< std::pair< int, int > > &track)
Definition: absgeo.cxx:62
int ncells_perplane
Definition: geo.cxx:22
int active_track
Definition: main.cxx:78
int screen_to_cell(const noe_view_t view, const int x, const int y)
Definition: geo.cxx:229
noe_view_t
Definition: geo.h:1
int gevi
Definition: main.cxx:76
int screen_to_plane(const noe_view_t view, const int x)
Definition: geo.cxx:207
static bool visible_hit(const int32_t tdc, const int TDCSTEP)
Definition: active.cxx:79
std::vector< screenvertex_t > screenvertices[kXorY]
Definition: active.cxx:24
std::vector< screentrack_t > screentracks[kXorY]
Definition: active.cxx:23