Commit 5ac81a1b authored by Nick Sauerwein's avatar Nick Sauerwein
Browse files

before oszi connection change

parent d52d12e3
......@@ -121,7 +121,7 @@ def movetoL(pos, direction):
def init():
cmd("SCLF0,500")#set close-loop frequency!!
cmd("SCLF1,10000")
cmd("SCLF1,150") # do not change this. Time is not important
cmd("SCLS0,100000000")
cmd("SCLS1,100000000")
......@@ -148,7 +148,7 @@ def init():
moverelL(-0.1)
time.sleep(3)
frmL("bwd")
frmL("fwd")
while cmd("GS1",output=True)[-2]!=str(3):
#print(cmd("GS0",output=True)[-2])
......
......@@ -8,7 +8,10 @@ config file:
channel: channel on DRS4 where Cup is connected to
amplification: factor amplification of signal before drs4
R: resistance of termination [Ohm]
n_calib: number of point to avarge over to find zero
t1: bound1 of integral (before peak up)
t2: bound2 of integral (between peak up and down)
t3: bound3 of integral (after shorter peak down)
measurement file:
time: time (datetime object)
......@@ -20,7 +23,12 @@ charge: charge [fC]
default_config = {'channel':2,
'R': 50.,
'amplification': 316}
'amplification': 316,
'n_calib': 100,
't1': 450.,
't2': 475.,
't3': 600.,
}
class FaradayCup:
#mendatory functions
......@@ -36,6 +44,10 @@ class FaradayCup:
config['channel'] = self.channel
config['amplification'] = self.amplification
config['R'] = self.R
config['n_calib'] = self.n_calib
config['t1'] = self.t1
config['t2'] = self.t2
config['t3'] = self.t3
return config
@config.setter
......@@ -43,7 +55,10 @@ class FaradayCup:
self.channel = config['channel']
self.R = config['R']
self.amplification = config['amplification']
self.n_calib = config['n_calib']
self.t1 = config['t1']
self.t2 = config['t2']
self.t3 = config['t3']
def measure(self):
import time as ttime
......@@ -54,16 +69,32 @@ class FaradayCup:
time = datetime.datetime.now()
measurement = {}
v_calib = np.mean(sig_uvolt[:,100])
v_calib = np.mean(sig_uvolt[:self.n_calib])
sig_uvolt = sig_uvolt - v_calib
charge = np.trapz(sig_uvolt, x = np.array(sig_time)*1e-9)*1e-6/self.R/self.amplification*1e15
measurement = {'time': time,'sig_time': sig_time, 'sig_uvolt': sig_uvolt, 'peak_uvolt': np.min(sig_uvolt),'charge': charge }
te = sig_time[-1]
charge_tot = self.integrate_charge(sig_time, sig_uvolt, sig_time[0], te)
charge1 = self.integrate_charge(sig_time, sig_uvolt, self.t1, self.t2)
charge2 = self.integrate_charge(sig_time, sig_uvolt, self.t2, self.t3)
charge3 = self.integrate_charge(sig_time, sig_uvolt, self.t3, te)
measurement = {'time': time,'sig_time': sig_time, 'sig_uvolt': sig_uvolt, 'peak_uvolt': np.min(sig_uvolt),'charge_tot': charge_tot, 'charge1': charge1, 'charge2': charge2,'charge3': charge3 }
return measurement
def plot_measure(self, measurement, config = None):
if self.plot_server == None:
self.plot_server = Plot1DServer({'title':'FaradayCup', 'xlabel':'Time [ns]', 'ylabel': 'Signal [uV]'})
self.plot_server.update(measurement['sig_time'], measurement['sig_uvolt'])
\ No newline at end of file
self.plot_server.update(measurement['sig_time'], measurement['sig_uvolt'])
def integrate_charge(self, sig_time, sig_uvolt, timea, timeb):
return np.trapz(sig_uvolt[np.logical_and(sig_time > timea, sig_time < timeb)], x = sig_time[np.logical_and(sig_time > timea, sig_time < timeb)]*1e-9)*1e-6/self.R/self.amplification*1e15
\ No newline at end of file
......@@ -41,7 +41,8 @@ def find_beam(im, plot = True, nFWHM = 2, axis = None):
px_box = 100
im_reduced = im[itmaxypx-px_box:itmaxypx+px_box, itmaxxpx-px_box:itmaxxpx+px_box]
im_reduced = im[max([itmaxypx-px_box,0]):min([itmaxypx+px_box, im.shape[0]]), max([itmaxxpx-px_box, 0]):min([itmaxxpx+px_box,im.shape[1]])]
#filter
from skimage.filters import gaussian
......
......@@ -14,7 +14,7 @@ home_on_connect: boolean
n_av: number of focus measurements per iteration
maxiter: maximal number of iterations
minint: minimal intensity to search for beam
focus_min: desired focus [um]
measurement file (n.a)
'''
......@@ -23,7 +23,8 @@ default_config = {'pos_Pay': 3.99396444,
'pos_Paz': 5.16051188,
'home_on_connect':True,
'n_av': 10,
'maxiter':20}
'maxiter':20,
'focus_min': 10.5}
class ParabolicMirror:
def __init__(self, config, FocusCamera, Periscope, Laser):
......@@ -53,7 +54,7 @@ class ParabolicMirror:
config['pos_Pay'] = float(self.Pay.position())
config['pos_Paz'] = float(self.Paz.position())
config['home_on_connect'] = self.home_on_connect
config['focus_min'] = self.focus_min
config['n_av'] = self.n_av
config['maxiter'] = self.maxiter
return config
......@@ -62,7 +63,7 @@ class ParabolicMirror:
def config(self,config):
self.Pay.goto(config['pos_Pay'])
self.Paz.goto(config['pos_Paz'])
self.focus_min = config['focus_min']
self.n_av = config['n_av']
self.maxiter = config['maxiter']
self.home_on_connect = config['home_on_connect']
......@@ -83,12 +84,12 @@ class ParabolicMirror:
self.optimize()
def optimize(self, wanted_focus_um = 8, sleep_time = 0.2, output = True):
def optimize(self, sleep_time = 0.2, output = True):
#this variable is necessary to compensate the attenuation of the laser
global intmult
intmult = 1.
wanted_focus_um = self.focus_min
maxiter = self.maxiter
n_av = self.n_av
......@@ -117,7 +118,7 @@ class ParabolicMirror:
print ('maxints: ',maxints)
print ('mean(maxits): ',np.mean(maxints))
res = np.sqrt((np.array(FWHMxs)**2 + np.array(FWHMys)**2)/2)#*4096/np.array(maxints)*intmult
res = np.sqrt((np.array(FWHMxs)**2 + np.array(FWHMys)**2)/2 + (np.array(FWHMxs) - np.array(FWHMys)) **2)#*4096/np.array(maxints)*intmult
mean, error = np.mean(res), np.std(res, ddof = -1)/np.sqrt(len(res))
global reduce_int
if np.mean(maxints) > 4e3:
......@@ -196,6 +197,7 @@ class ParabolicMirror:
'return_all': False,
'fatol': wanted_focus_um**2})
opt_f(res.x)
......
File mode changed from 100644 to 100755
This diff is collapsed.
No preview for this file type
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -5,10 +5,17 @@
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Widget Javascript not detected. It may not be installed or enabled properly.\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c8628717c2e840568147ea4df98e383d"
"model_id": "6138d23dfda64266bdf77dd488a690e7"
}
},
"metadata": {},
......
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment