geo.cxx
Go to the documentation of this file.
1 #include <utility>
2 #include <vector>
3 #include <stdint.h>
4 #include "event.h"
5 #include "geo.h"
6 
7 static const int NDnplanes_perview = 8 * 12 + 11,
8  NDfirst_mucatcher = 8 * 24,
9  NDncells_perplane = 3 * 32;
10 static const int FDnplanes_perview = 16 * 28,
11  FDfirst_mucatcher = 9999, // i.e. no muon catcher
12  FDncells_perplane = 12 * 32;
13 
16 
17 // We're going to assume the ND until we see a hit that indicates it's FD
18 bool isfd = false;
19 
25 
26 // The screen coordinates of the x and y view and muon catcher cutout,
27 // from the upper left corner of the border to the lower right corner
28 // of the inside.
30 
31 static const double ExtruDepth = 66.1 ; // mm
32 static const double ExtruWallThick = 5.1 ;
33 static const double ModuleGlueThick = 0.379;
34 static const double FDBlockGap = 4.5 ;
35 static const double NDBlockGap = 6.35 ;
36 
37 static const int FD_planes_per_block = 32;
38 static const int ND_planes_per_block = 24;
39 
40 static const double ExtruWidth = 634.55;
41 static const double ExtruGlueThick = 0.48;
42 
43 static const double mean_block_gap_per_plane =
45 
47 
48 
49 // Given 'y', the number of vertical pixels we will use for each cell,
50 // return the number of horizontal pixels we will use.
51 int pixx_from_pixy(const int y)
52 {
53  const double meancellwidth = (2*ExtruWidth+ExtruGlueThick)/32;
54 
55  // Comes out to 3.36, giving pixel ratios 3:1, 2:7, 3:10, 4:13, 5:17, etc.
56  const double planepix_per_cellpix = 2*celldepth/meancellwidth;
57 
58  return int(y*planepix_per_cellpix + 0.5);
59 }
60 
61 int scintpix_from_pixx(const int x)
62 {
63  const double scintdepth = ExtruDepth - 2*ExtruWallThick;
64  return int(x * scintdepth/(2*celldepth) + 0.5);
65 }
66 
67 int total_x_pixels(const int pixels_x)
68 {
69  return pixels_x*(nplanes_perview +
71  nplanes_perview - first_mucatcher/2: 0)) + 1;
72 }
73 
74 int total_y_pixels(const int pixels_y)
75 {
76  return ncells_perplane*pixels_y
77  + pixels_y/2 /* cell stagger */ + 1 /* border */;
78 }
79 
80 void setfd()
81 {
82  isfd = true;
83 
87 
89 
90  pixx = FDpixx;
91  pixy = FDpixy;
92 
93  setboxes();
94 }
95 
96 // When we're zoomed, this stores the amount to the left of the screen
97 // that the left/top of the first plane/cell is.
99 
100 int det_to_screen_x(const int plane)
101 {
102  const bool xview = plane%2 == 1;
103  return 1 + // Don't overdraw the border
104  pixx*((plane
105 
106  // space out the muon catcher planes so they are twice as far
107  // apart as normal. This is very close to right, since the depth
108  // of (two scintillator planes + one steel plane + air gaps) is
109  // within 10% of the depth of two scintillator planes.
110  +(plane > first_mucatcher?plane-first_mucatcher:0))/2)
111 
112  // stagger x and y planes
113  + xview*pixx/2
114 
115  - screenxoffset;
116 }
117 
118 // XXX put in the extra space between extrusions.
119 int det_to_screen_y(const int plane, const int cell)
120 {
121  const bool xview = plane%2 == 1;
122 
123  // In each view, every other plane is offset by half a cell width
124  const bool celldown = !((plane/2)%2 ^ (plane%2));
125 
126  return + pixy*(ncells_perplane-cell) // cells numbered from the bottom
127 
128  - (pixy-1)
129 
130  // Physical stagger of planes in each view, but not in the muon
131  // catcher, which is a better approximation to the current MC
132  // geometry and plausible from visual inspection of the real
133  // muon catcher.
134  + (plane < first_mucatcher)*celldown*pixy/2
135 
137 }
138 
139 std::pair<int, int> cppoint_to_screen(const cppoint & tp)
140 {
141  return std::pair<int, int>(
142  det_to_screen_x(tp.plane) + (0.5 + tp.fplane)*pixx/2,
143  det_to_screen_y(tp.plane, tp.cell) + (0.5 - tp.fcell )*pixy
144  );
145 }
146 
147 // Calculate the size of the bounding boxes for the detector's x and y
148 // views, plus the muon catcher cutaway.
149 void setboxes()
150 {
151  const int ybox = total_y_pixels(pixy);
152  const int xbox = total_x_pixels(pixx);
153 
154  const int xboxnomu = pixx*(first_mucatcher/2) + pixy/2 /* cell stagger */;
155 
156  // muon catcher is 1/3 empty. Do not include cell stagger here since we want
157  // the extra half cells to be inside the active box.
158  const int yboxnomu = (ncells_perplane/3)*pixy;
159 
160  screenview[kX].xmin = -screenxoffset + pixx/2 /* plane stagger */;
161  screenview[kX].ymin = -screenyoffset_xview;
162  screenview[kX].xsize = xbox;
163  screenview[kX].ysize = ybox;
164 
165  const bool hasmucatch = first_mucatcher < nplanes;
166 
167  // In the x view the blank spaces are to the left of the hits, but in
168  // the y view, they are to the right, but I don't want the box to include them.
169  const int hacky_subtraction_for_y_mucatch = hasmucatch * pixx;
170 
171  screenview[kY].xmin = -screenxoffset;
172  screenview[kY].ymin = -screenyoffset_yview;
173  screenview[kY].xsize = xbox-hacky_subtraction_for_y_mucatch;
174  screenview[kY].ysize = ybox;
175 
176  screenmu.xmin = -screenxoffset + 1 + xboxnomu;
177  screenmu.ymin = -screenyoffset_yview;
178  screenmu.xsize = xbox-xboxnomu-hacky_subtraction_for_y_mucatch-1;
179  screenmu.ysize = yboxnomu;
180 }
181 
183 {
184  // Where x would be if not offset
185  const int unoffsetx = x + screenxoffset;
186 
187  // The number of the first muon catcher plane counting only planes
188  // in one view.
189  const int halfmucatch = (first_mucatcher)/2 + (view == kY);
190 
191  // Account for the plane stagger and border width.
192  const int effx = unoffsetx - 2 -
193  (unoffsetx-2 >= halfmucatch*pixx)*(pixx/2);
194 
195  // Half the plane number, as long as we're not in the muon catcher
196  int halfp = view == kX? (effx-pixx/2)/pixx
197  :( effx )/pixx;
198 
199  // Fix up the case of being in the muon catcher
200  if(halfp > halfmucatch) halfp = halfmucatch +
201  (halfp - halfmucatch)/2;
202 
203  // The plane number, except it might be out of range
204  return halfp*2 + (view == kX);
205 }
206 
207 int screen_to_plane(const noe_view_t view, const int x)
208 {
209  const int p = screen_to_plane_unbounded(view, x);
210  if(p < (view == kX?1:0)) return -1;
211  if(p >= nplanes) return -1;
212  return p;
213 }
214 
215 int screen_to_cell_unbounded(const noe_view_t view, const int x, const int y)
216 {
217  // Where y would be if not offset. Do not pass into functions.
218  const int unoffsety = y + (view == kX?screenyoffset_xview:screenyoffset_yview);
219 
220  const int plane = screen_to_plane(view, x);
221 
222  // See comments in det_to_screen_y() on the muon catcher.
223  const bool celldown = (plane < first_mucatcher) && !((plane/2)%2 ^ (plane%2));
224  const int effy = unoffsety - celldown*(pixy/2) - 2;
225 
226  return ncells_perplane - effy/pixy - 1;
227 }
228 
229 int screen_to_cell(const noe_view_t view, const int x, const int y)
230 {
231  const int c = screen_to_cell_unbounded(view, x, y);
232  const int plane = screen_to_plane(view, x);
233  if(c < 0) return -1;
234  if(c >= ncells_perplane) return -1;
235  if(plane >= first_mucatcher && view == kY && c >= 2*ncells_perplane/3) return -1;
236  return c;
237 }
int pixy
Definition: geo.cxx:24
static const double ExtruWallThick
Definition: geo.cxx:32
float fcell
Definition: event.h:16
void setboxes()
Definition: geo.cxx:149
int pixx_from_pixy(const int y)
Definition: geo.cxx:51
Supply basic geometry functions.
static const double ExtruWidth
Definition: geo.cxx:40
Definition: geo.h:1
int pixx
Definition: geo.cxx:24
const char * p
Definition: xmltok.h:285
int xmin
Definition: geo.h:4
uint16_t plane
Definition: event.h:11
int nplanes_perview
Definition: geo.cxx:20
int first_mucatcher
Definition: geo.cxx:21
static const int FDncells_perplane
Definition: geo.cxx:12
int xsize
Definition: geo.h:5
int ymin
Definition: geo.h:4
int NDpixx
Definition: geo.cxx:15
int screenyoffset_xview
Definition: geo.cxx:98
int FDpixy
Definition: geo.cxx:14
int screenxoffset
Definition: geo.cxx:98
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;})
static const int NDnplanes_perview
Definition: geo.cxx:7
static const int FD_planes_per_block
Definition: geo.cxx:37
rect screenview[kXorY]
Definition: geo.cxx:29
void setfd()
Definition: geo.cxx:80
float fplane
Definition: event.h:16
int ncells_perplane
Definition: geo.cxx:22
static const double FDBlockGap
Definition: geo.cxx:34
static const double ExtruGlueThick
Definition: geo.cxx:41
static const double ModuleGlueThick
Definition: geo.cxx:33
int screenyoffset_yview
Definition: geo.cxx:98
int nplanes
Definition: geo.cxx:23
static const int NDncells_perplane
Definition: geo.cxx:9
static const int FDfirst_mucatcher
Definition: geo.cxx:11
int total_y_pixels(const int pixels_y)
Definition: geo.cxx:74
static const int NDfirst_mucatcher
Definition: geo.cxx:8
static const int ND_planes_per_block
Definition: geo.cxx:38
rect screenmu
Definition: geo.cxx:29
int det_to_screen_y(const int plane, const int cell)
Definition: geo.cxx:119
int FDpixx
Definition: geo.cxx:14
static const int FDnplanes_perview
Definition: geo.cxx:10
std::pair< int, int > cppoint_to_screen(const cppoint &tp)
Definition: geo.cxx:139
Definition: geo.h:3
int ysize
Definition: geo.h:5
static const double mean_block_gap_per_plane
Definition: geo.cxx:43
Definition: geo.h:1
static const double NDBlockGap
Definition: geo.cxx:35
static const double celldepth
Definition: geo.cxx:46
int scintpix_from_pixx(const int x)
Definition: geo.cxx:61
int total_x_pixels(const int pixels_x)
Definition: geo.cxx:67
bool isfd
Definition: geo.cxx:18
int screen_to_cell(const noe_view_t view, const int x, const int y)
Definition: geo.cxx:229
int det_to_screen_x(const int plane)
Definition: geo.cxx:100
noe_view_t
Definition: geo.h:1
int screen_to_plane_unbounded(const noe_view_t view, const int x)
Definition: geo.cxx:182
int screen_to_cell_unbounded(const noe_view_t view, const int x, const int y)
Definition: geo.cxx:215
int screen_to_plane(const noe_view_t view, const int x)
Definition: geo.cxx:207
Definition: event.h:9
static const double ExtruDepth
Definition: geo.cxx:31
uint16_t cell
Definition: event.h:11
int NDpixy
Definition: geo.cxx:15