diff --git a/script/Alignment/Gun_solenoid_alignment_dv.py b/script/Alignment/Gun_solenoid_alignment_dv.py new file mode 100644 index 0000000..ebd05af --- /dev/null +++ b/script/Alignment/Gun_solenoid_alignment_dv.py @@ -0,0 +1,37 @@ +#Tool to align the laser on the cathode. +# S. Bettoni, A. Gobbo, D. Voulot +#10/05/2016 + + +#Procedure: + #I switch off all the magnets between the gun solenoid and the screen or BPM used for the measurement + #I change the current of the gun soleoid + #I look at the centroid position (BPM or screen) downstream of the gun. + +gun_sol_I = Channel("SINEG01-MSOL130:I-SET") +center_x, center_y = ... # some camtool command or channel? +bpm_x = Channel("SINEG01-DBPM340:X1") +bpm_y = Channel("SINEG01-DBPM340:Y1") + +start_I = 20 +end_I = 150 +step_I = 1 + +# Enable gun laser +caput("SIN-CVME-TIMAST-TMA:Beam-laser-On", 1) + +#Scan using the screen +r = lscan(gun_sol_I, [center_x, center_y], start_I, end_I, step_I, latency = 0.5) +#Scan using the BPM +#r = lscan(gun_sol_current, [bpm_x, bpm_y], start_I, end_I, step_I, latency = 0.5) + +# Disable gun laser +caput("SIN-CVME-TIMAST-TMA:Beam-laser-On", 0) + +#I take the result of the scan and I do the plots +x = r.getReadable(0) +y = r.getReadable(1) +plot(y, xdata=x, title = "CM") + +#I save the entry in the logbook + diff --git a/script/local.py b/script/local.py index 3750aac..e022b07 100755 --- a/script/local.py +++ b/script/local.py @@ -2,144 +2,148 @@ # Deployment specific global definitions - executed after startup.py ################################################################################################### -from mathutils import estimate_peak_indexes, fit_gaussians, create_fit_point_list, Gaussian -from mathutils import fit_polynomial,fit_gaussian, fit_harmonic, calculate_peaks -from mathutils import PolynomialFunction, Gaussian, HarmonicOscillator - -import java.awt.Color as Color - - -def fit(ydata, xdata = None): - """ - """ - if xdata is None: - xdata = frange(0, len(ydata), 1) - max_y= max(ydata) - index_max = ydata.index(max_y) - max_x= xdata[index_max] - print "Max index:" + str(index_max), - print " x:" + str(max_x), - print " y:" + str(max_y) - gaussians = fit_gaussians(ydata, xdata, [index_max,]) - (norm, mean, sigma) = gaussians[0] - p = plot([ydata],["data"],[xdata], title="Fit" )[0] - fitted_gaussian_function = Gaussian(norm, mean, sigma) - scale_x = [float(min(xdata)), float(max(xdata)) ] - points = max((len(xdata)+1), 100) - resolution = (scale_x[1]-scale_x[0]) / points - fit_y = [] - fit_x = frange(scale_x[0],scale_x[1],resolution, True) - for x in fit_x: - fit_y.append(fitted_gaussian_function.value(x)) - p.addSeries(LinePlotSeries("fit")) - p.getSeries(1).setData(fit_x, fit_y) - - if abs(mean - xdata[index_max]) < ((scale_x[0] + scale_x[1])/2): - print "Mean -> " + str(mean) - p.addMarker(mean, None, "Mean="+str(round(norm,2)), Color.MAGENTA.darker()) - return (norm, mean, sigma) - else: - p.addMarker(max_x, None, "Max="+str(round(max_x,2)), Color.GRAY) - print "Invalid gaussian fit: " + str(mean) - return (None, None, None) - - -def hfit(ydata, xdata = None): - if xdata is None: - xdata = frange(0, len(ydata), 1) - - max_y= max(ydata) - index_max = ydata.index(max_y) - max_x= xdata[index_max] - - start,end = min(xdata), max(xdata) - (amplitude, angular_frequency, phase) = fit_harmonic(ydata, xdata) - fitted_harmonic_function = HarmonicOscillator(amplitude, angular_frequency, phase) - - print "amplitude = ", amplitude - print "angular frequency = ", angular_frequency - print "phase = ", phase - - f = angular_frequency/ (2* math.pi) - print "frequency = ", f - - resolution = 0.01 - fit_y = [] - for x in frange(start,end,resolution, True): - fit_y.append(fitted_harmonic_function.value(x)) - fit_x = frange(start, end+resolution, resolution) - - p = plot(ydata,"data", xdata, title="HFit")[0] - p.addSeries(LinePlotSeries("fit")) - p.getSeries(1).setData(fit_x, fit_y) - - #m = (phase + math.pi)/ angular_frequency - m = -phase / angular_frequency - if (m " + str(mean) + p.addMarker(mean, None, "Mean="+str(round(norm,2)), Color.MAGENTA.darker()) + return (norm, mean, sigma) + else: + p.addMarker(max_x, None, "Max="+str(round(max_x,2)), Color.GRAY) + print "Invalid gaussian fit: " + str(mean) + return (None, None, None) + + +def hfit(ydata, xdata = None): + """ + Harmonic fit + """ + if xdata is None: + xdata = frange(0, len(ydata), 1) + + max_y= max(ydata) + index_max = ydata.index(max_y) + max_x= xdata[index_max] + + start,end = min(xdata), max(xdata) + (amplitude, angular_frequency, phase) = fit_harmonic(ydata, xdata) + fitted_harmonic_function = HarmonicOscillator(amplitude, angular_frequency, phase) + + print "amplitude = ", amplitude + print "angular frequency = ", angular_frequency + print "phase = ", phase + + f = angular_frequency/ (2* math.pi) + print "frequency = ", f + + resolution = 0.01 + fit_y = [] + for x in frange(start,end,resolution, True): + fit_y.append(fitted_harmonic_function.value(x)) + fit_x = frange(start, end+resolution, resolution) + + p = plot(ydata,"data", xdata, title="HFit")[0] + p.addSeries(LinePlotSeries("fit")) + p.getSeries(1).setData(fit_x, fit_y) + + #m = (phase + math.pi)/ angular_frequency + m = -phase / angular_frequency + if (m