{"id":27,"date":"2017-10-11T15:51:23","date_gmt":"2017-10-11T19:51:23","guid":{"rendered":"http:\/\/sites.nd.edu\/attpc\/?p=27"},"modified":"2017-10-11T15:51:23","modified_gmt":"2017-10-11T19:51:23","slug":"vertexanalyzor-py","status":"publish","type":"post","link":"https:\/\/sites.nd.edu\/attpc\/2017\/10\/11\/vertexanalyzor-py\/","title":{"rendered":"VertexAnalyzor.py"},"content":{"rendered":"<p>The overall functions should be used in the sequence below<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1318\" src=\"http:\/\/www.jianping-lai.com\/wp-content\/uploads\/Physics\/ATTPC\/VertexAnalyzor\/VertexAnalyzor_flow-e1507559481268.png\" alt=\"\" width=\"220\" height=\"500\" \/><\/p>\n<p>Each of the functions calls sub functions in the flow presented in the graph below<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1320\" src=\"http:\/\/www.jianping-lai.com\/wp-content\/uploads\/Physics\/ATTPC\/VertexAnalyzor\/VertexAnalyzor_functions-e1507563086293.png\" alt=\"\" width=\"728\" height=\"500\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>An example of the original image is shown below,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1350\" src=\"http:\/\/www.jianping-lai.com\/wp-content\/uploads\/Physics\/ATTPC\/VertexAnalyzor\/original_image.png\" alt=\"\" width=\"480\" height=\"300\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>FilterBackground(image):<\/strong> as the image is messy, this function take the connected convexHull to clean up everything outside this hull.<\/p>\n<p>image (numpy 2d uint8 array): the original image<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1362\" src=\"http:\/\/www.jianping-lai.com\/wp-content\/uploads\/Physics\/ATTPC\/VertexAnalyzor\/filtered_image-1.png\" alt=\"\" width=\"480\" height=\"300\" \/><\/p>\n<p><strong>GetEventPositions(pic,debug_mode=0, center_width = 12, quadrant_thresh=100, center_thresh=300, err_thresh =12, spread_thresh=6 ):<\/strong>\u00a0get all the three tip points and also the vertex point<\/p>\n<p>pic (numpy 2d uint8 array): the original image<br \/>\ndebug_mode (bool): plot some debug features, this should be turned off in batch mode<br \/>\ncenter_width (float): not used for now<br \/>\nquadrant_thresh (float): threshold for number of pixel in the reaction product part<br \/>\ncenter_thresh (float):\u00a0threshold for the beam part<br \/>\nerr_thresh (float):\u00a0 threshold for average distance to the fit<br \/>\nspread_thresh (float): threshold for x,y spread out<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1360\" src=\"http:\/\/www.jianping-lai.com\/wp-content\/uploads\/Physics\/ATTPC\/VertexAnalyzor\/post_image.png\" alt=\"\" width=\"509\" height=\"350\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>AveDist(x,y,k,b):\u00a0<\/strong>calculate the average distance from (x,y) to a straight line with (k,b) parameters.<\/p>\n<p>x (numpy float array): the x positions<br \/>\ny (numpy float array): the y positions<br \/>\nk (float): the slope of the line<br \/>\nb (float): the y-intercept of the line<\/p>\n<p>return (float): average distance from (x,y) to the line (k,b)<\/p>\n<p><strong>r2(x,y,k,b):\u00a0<\/strong>just to calculate the r2 score of the fitting<\/p>\n<p>parameters are the same to function above<\/p>\n<p>return (float): r2 score<\/p>\n<p>&nbsp;<\/p>\n<p><strong>VertexPos(fits,y0): <\/strong>using all fitting results and the y position from the right most tip point to estimate the vertex position<\/p>\n<p>The function divide the calculation to 2 scenarios. 1. you have 2 or 3 fitted lines, then you just pick the parameters of the first two lines for the calculation. 2. if you have only 1 line and this one will not be you center line (because of previous fitting condition), you assume the center line is straight on y0.<\/p>\n<p>fits ([int,float,float,float]*3): fit results for three parts of the image<\/p>\n<p>return (float,float): (x,y)<\/p>\n<p>&nbsp;<\/p>\n<p><strong>tbjcfit(xs,ys):\u00a0<\/strong>use SVD to calculate the least square DISTANCE (not y) fitting<\/p>\n<p>xs (numpy float array): the x positions<br \/>\nys (numpy float array): the y positions<\/p>\n<p>return (int,float,float,float):(number of pixels, k,b,average distance)<\/p>\n<p>&nbsp;<\/p>\n<p><strong>GetFit(image_, part_thresh=60, err_thresh =1.2,spread_thresh=6):<\/strong> this function extract the x,y positions of each pixel above 0 value. Then fit the x,y points using tbjcfit. The results will be filtered through a few conditions to see if the fitting is good, like if the average distance from the points to the line is within the err_thresh and if the scattered positions does give a reasonable line shape distribution.<\/p>\n<p>image_ (numpy 2d uint8 array): the part of the image you want to obtain a line fitting<br \/>\npart_thresh (float): if the number of pixels in the image is large enough for a fitting<br \/>\nerr_thresh (float):the average distance to the fitting line of all the points<br \/>\nspread_thresh (float):the threshold for requiring a spread out distributed data on either x or y axis<\/p>\n<p>return (numpy 2d uint8 array): a copy of filtered image<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>GetLineInfo(p1,p2, L_thre = -5):\u00a0<\/strong>calculate the length and angle between two points<\/p>\n<p>p1 (float,float): the tip point<br \/>\np2\u00a0(float,float): the vertex point<br \/>\nL_thre = -5: not used for now<\/p>\n<p><strong>GetEventInfo(points,p0):\u00a0<\/strong>calculate the length and angle for between each pair of the tip point and the vertex point<\/p>\n<p>points ((float,float)*3): the positions of the tip points<br \/>\np0 (float,float): the position of the vertex point<\/p>\n<p>return ((float,float)*3,float): (theta,length) for each pair, and the reaction range<\/p>\n<p><strong>Distance(contours,n1,n2):<\/strong> calculate the minimum distance between two contour<\/p>\n<p>contours [numpy.array (n,1,2)]:all the contours<br \/>\nn1 (int):\u00a0index of the first contour<br \/>\nn2 (int): index of the second contour<\/p>\n<p>return (float): the minimum distance<\/p>\n<p><strong>Groups(contours):\u00a0<\/strong>combine all adjacent contours<\/p>\n<p>contours [numpy.array (n,1,2)]:all the contours<\/p>\n<p>return ((float)*n, (float)*n): grouped contours<\/p>\n<p><strong>convexHull(thresh, debug_mode = 0):\u00a0<\/strong>calculated the convexHull using the largest grouped contour<\/p>\n<p>thresh (numpy 2d uint8 array): image after preliminary processing<\/p>\n<p>return ((float,float)*n): the hull points<\/p>\n<p><strong>MaxEnclosedTriangle(hull):\u00a0<\/strong>calculate the maximum enclosed triangle using the hull points<\/p>\n<p>hull ((float,float)*n):\u00a0the hull points<\/p>\n<p>return (int, int, int): index of the hull points to form the maximum enclosed triangle<\/p>\n<p><strong>TipFinder(thresh, debug_mode = 0):\u00a0<\/strong>return the position of the tip on the\u00a0maximum enclosed triangle<\/p>\n<p>thresh (numpy 2d uint8 array): image after preliminary processing<\/p>\n<p>return ((float,float)*3):\u00a0the position of the tip on the\u00a0maximum enclosed triangle<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The overall functions should be used in the sequence below Each of the functions calls sub functions in the flow presented in the graph below &nbsp; An example of the original image is shown below, &nbsp; FilterBackground(image): as the image &hellip; <a href=\"https:\/\/sites.nd.edu\/attpc\/2017\/10\/11\/vertexanalyzor-py\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2309,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[264463],"tags":[],"class_list":["post-27","post","type-post","status-publish","format-standard","hentry","category-attpcanalysis"],"_links":{"self":[{"href":"https:\/\/sites.nd.edu\/attpc\/wp-json\/wp\/v2\/posts\/27","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sites.nd.edu\/attpc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sites.nd.edu\/attpc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sites.nd.edu\/attpc\/wp-json\/wp\/v2\/users\/2309"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.nd.edu\/attpc\/wp-json\/wp\/v2\/comments?post=27"}],"version-history":[{"count":1,"href":"https:\/\/sites.nd.edu\/attpc\/wp-json\/wp\/v2\/posts\/27\/revisions"}],"predecessor-version":[{"id":28,"href":"https:\/\/sites.nd.edu\/attpc\/wp-json\/wp\/v2\/posts\/27\/revisions\/28"}],"wp:attachment":[{"href":"https:\/\/sites.nd.edu\/attpc\/wp-json\/wp\/v2\/media?parent=27"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.nd.edu\/attpc\/wp-json\/wp\/v2\/categories?post=27"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.nd.edu\/attpc\/wp-json\/wp\/v2\/tags?post=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}