Submodule core¶
Internal functions called by the fit function in module LordOfRings.ringfit.multi_ring_fit
- LordOfRings.core.CUDA_fit(file_name, triplet_file_name, dict_events, maxhits, triplet_threshold, ptolemy_threshold, rsearch, drsearch)¶
CUDA_fit manages the gpu function call, defining the structure of threads and blocks and allocating the necessary memory, this function is called by the function multi_ring_fit and should not be called directly by the user.
- Parameters
- file_namestring
String containing the name of the file with the cuda fit Kernel.
- triplet_file_namestring
String containing the name of the file with the cuda triplet search Kernel.
- maxhitsint
Maximum number of points per event (i.e. the maximum number of ones in each sparse matrix).
- triplet_thresholdfloat
Minimum distance between two points of the same triplet.
- ptolemy_thresholdfloat
Maximum value of the difference defined by the Ptolemy theorem: the points for which this difference is greater than ptolemy_threshold are excluded by the fit algorithm.
- rsearchfloat
The radius that will be searched in the data after the fit, if zero the fourth argument returned by the function will be an empty numpy array.
- drsearchfloat
The error on the radius rsearch, the function will return all the events having a fitted radius in (rsearch - drsearch, rsearch + drsearch)
- Returns
- (1d numpy-array, 1d numpy-array, 1d numpy array) [float, float, float]
Array of Radius, Xcenters, Ycenters of lenght 4 * nevents. Each event has four prediction of center and radius, one for each triplet evaluated (4 triplet for event).
- LordOfRings.core.CudaFindTriplet(dict_events, maxhits=64, threshold=10)¶
CudaFindTriplet uses the GPU to find the triplets that will be used in Ptolemy’s theorem to fit the circle. It gives also the x and y coordinates of hits for all events.
- Parameters
- dict_eventsdictionary
Dictionary whose keys are the name of .txt files and whose values are the x, y coordinates of the relative event in a list. This format is the output of the function LordOfRing.ringfit.load_data.
- maxhitsint
Maximum number of points per event (i.e. the maximum number of ones in each sparse matrix). Default is 64.
- thresholdfloat
Treshold value for the selection of the triplets, it defines the minimum reciprocal distance of the three points in the same triplet. Default is 10.
- Returns
- ( 1d numpy-array, 1d numpy-array, 1d numpy-array ) [int, float, float]
The triplet and the coordinates in a tuple (triplet, X, Y).
- LordOfRings.core.GPU_enabled()¶
This function say to the user if the GPU is able to compute or if the installation of pycuda went wrong with a boolean variable.
- Returns
- GPUBoolean
If GPU is True the the GPU is able to compute, else there as been an error in the installation of pycuda.
- LordOfRings.core.init_triplets(dict_events, maxhits=64, t=10, GPU=False)¶
init_triplets gives three array: the first contains the index of border hits in the sparse matrix of each event whose reciprocal distance is greater then t,the second contains the x coordinates of hits for all events in a single array, the third contains the y coordinates as before.
- Parameters
- dict_eventsdictionary
Dictionary whose keys are the name of .txt files and whose values are the x, y coordinates of the relative event in a list. This format is the output of the function LordOfRing.ringfit.load_data.
- maxhitsint
Maximum number of points per event (i.e. the maximum number of ones in each sparse matrix).
- tfloat
Treshold value for the selection of the triplets, it defines the minimum reciprocal distance of the three points in the same triplet.
- GPUBoolean
If GPU is True the triplet are extracted with CUDA on GPU, else they are extracted whit a loop on the events and the numpy funtion. Default is False.
- Returns
- ( 1d numpy-array, 1d numpy-array, 1d numpy-array ) [int, float, float]
The triplet and the coordinates in a tuple (triplet, X, Y).
- LordOfRings.core.ptolemy_candidates(triplet, X, Y, idx_event, idx_trip, thr, nevents, maxhits)¶
This function is able to find the points that respect the ptolemy theorem giving a triplet and an event.
- Parameters
- triplet1d numpy-array of size (4 * 3 * nevent) [float]
Contain the indexs of the triplets chosen for the application of the Ptolemy theorem for each event (generated with LorfOfRings.ringfit.init_triplet).
- X1d numpy-array of size (MAXHITS * nevent) [float]
The x coordinates of ones in all the sparse matrix (generated with LorfOfRings.ringfit.init_triplet).
- Y1d numpy-array of size (MAXHITS * nevent) [float]
The y coordinates of ones in all the sparse matrix (generated with LorfOfRings.ringfit.init_triplet).
- idx_eventint
Index of the event analized in this function.
- idx_tripint
Index of the triplet relative to the event ‘idx_event’ analized in this function.
- thrfloat
Threshold for the Ptolemy theorem: if a point fits in the equation of the theorem with a maximal deviation of ‘thr’ it is stored as a good candidate for the triplet ‘idx_trip’.
- neventsint
The total number of events in the dataset analized.
- maxhitsint
Maximum number of points per event (i.e. the maximum number of ones in each sparse matrix).
- Returns
- (1d numpy-array, 1d numpy-array, 1d numpy-array, 1d numpy-array)
- [float, float, int, float]
The X, Y coordinates of the candidates to the circle fit, the index of the coordinates of the triplet relative to that event, the coordinates of the triplet in the same format passed to the function pypto ([Ax, Ay, Bx, By, Cx, Cy]).
- LordOfRings.core.py_fit(X, Y, triplet, maxhits, nevents, thr, min_pts, rsearch, drsearch)¶
This function loops over the event executing sequentially a number ‘nevents’ of fits in python (optimized with numpy).
- Parameters
- X1d numpy-array of size (MAXHITS * nevent) [float]
The x coordinates of ones in all the sparse matrix (generated with LorfOfRings.ringfit.init_triplet).
- Y1d numpy-array of size (MAXHITS * nevent) [float]
The y coordinates of ones in all the sparse matrix (generated with LorfOfRings.ringfit.init_triplet).
- triplet1d numpy-array of size (4 * 3 * nevent) [float]
Contain the indexs of the triplets chosen for the application of the Ptolemy theorem for each event (generated with LorfOfRings.ringfit.init_triplet).
- maxhitsint
Maximum number of points per event (i.e. the maximum number of ones in each sparse matrix).
- neventsint
The total number of events in the dataset analized.
- thrfloat
Threshold for the Ptolemy theorem: if a point fits in the equation of the theorem with a maximal deviation of ‘thr’ it is stored as a good candidate for the triplet ‘idx_trip’.
- min_pts
Minimum lenght of Xca, Yca for execute the fit, this parameter is for remove unaccurated fits.
- rsearchfloat
The radius that will be searched in the data after the fit, if zero the fourth argument returned by the function will be an empty numpy array. If zero no radius will be searched. Default is 0.
- drsearchfloat
The error on the radius rsearch, the function will return all the events having a fitted radius in (rsearch - drsearch, rsearch + drsearch). Default is 0.
- Returns
- (2d numpy-array, 2d numpy-array, 2d numpy array) [float, float, float]
Array of Radius, Xcenters, Ycenters of lenght nevents. Each event has four prediction of center and radius, one for each triplet evaluated (4 triplet for event). For this reason the result’s arrays are 2d: different rows index different event, different columns index different triplet.
- LordOfRings.core.pypto(x, y, trip)¶
This function returns the “ptolemy value” given four points x and y are single coordinates, trip contain 6 coordinates, 3 for the x and 3 for the y coordinates of the points of the triplet.
- Parameters
- xfloat or 1d numpy-array [float]
x coordinates of the point D in the Ptolemy Theorem
- yfloat or 1d numpy-array [float]
y coordinates of the point D in the Ptolemy Theorem
- tripl: list of float
List containing the coordinates of the triplet points A, B, C: [Ax, Ay, Bx, By, Cx, Cy]
- Returns
- float or 1d numpy-array [float]
The Ptolemy value (or values in case of x, y as array).
- LordOfRings.core.taubin(Xca, Yca, min_pts)¶
This function execute the circle fit of a single event with the Taubin’s Method.
- Parameters
- Xca1d numpy-array [float]
x coordinates of points of the circle for the fit.
- Yca1d numpy-array [float]
y coordinates of points of the circle for the fit.
- min_pts
Minimum lenght of Xca, Yca for execute the fit, this parameter is for remove unaccurated fits. It has to be greater then 3.
- Returns
- (1d numpy-array, 1d numpy-array, 1d numpy-array)
The radius, Xc, Yc evaluated by the fit rutine.