Skip to content
Matthew Bales edited this page Nov 25, 2016 · 10 revisions

SRK (Spin Runge Kutta) Analysis

Purpose

For study of spin precession and geometric phases in chambered EDM experiments. Integrates a classical equation of spin precession while transporting particles with reflections inside a chamber. Simplistic by design and fast.

Components

There are two primary components in this repository:

  1. The SRK Analysis library which provides interaction with a sqlite3 run database.
  2. Analysis notebooks which contain explorations and plots related to analysis of SRK

Run Database

SRKAnalysis tracks the input and output of SRK runs using an SQLite database. This database contains all macro command inputs used to generate the run as well as any summary information (mean average of angles, standard deviation, functional fits etc.) that can be analyzed. Runs can be created based on information from the database and summary information can be easily plotted.

The database used by Matthew Bales for research on non-Gaussian distributions in spin precession is called nedmAnalysis.sqlite . The columns of this database could be used as a starting point for a new database.

Setup

  1. Dependencies - Download and install all dependencies

A. Python 2.7 and additional libraries (consider Anaconda for simple installation/management): * paramiko * sqlite3 * matplotlib * numpy

B. ROOT * Tested with version 5.34.36.

  1. Database - Either setup a new run database or utilize an existing one. I recommend using sqliteman for creation or editing.

  2. Paths - Setup all paths for your computer located in srkglobal.py

Operation

Matt recorded most of the commands he used for analysis in srkrunlog.py. What follows is an example of python commands to do common tasks.

Adding a run to the database, creating the macro, and running it on optima. import srkdata import srkmisc import srkmultiprocessing import srkanalysis import sqlite3 import numpy as np from datetime import date import time import srkglobal

start_time = time.time()
today = date.today()

s = srkdata.default_srk_settings()
r = srkdata.default_run_settings()
srkglobal.set_computer("work_laptop")

# SRK settings and run settings
r['Title'] = "Wall Depol in Bernd's Hg Setup Test"
r['SRKVersion'] = '7dc2443902b6324aed9645abb367858138327163'
r['Date'] = today.strftime('%m/%d/%y')
r['RunType'] = 'parOnly'
r['NumTracksPer'] = 10000
s['VelProfHistPath'] = '!293.15'
s['ChamberRadius']=0.025
s['ChamberHeight']=0.10
s['ChamberRotation'] = '0. 90. 0.'
s['E0FieldStrength']=0
s['B0FieldStrength']=1e-6
s['BGradFieldStrength']=0
s['RecordAllSteps']=1
s['PeriodicStopTime']=0.00333333
s['TimeLimit']=100

# Create runs for different wall depolarization probabilities
wall_depol=srkmisc.even_sample_over_log(0.000001, 0.00001, 4)
for x in wall_depol:
    s['DepolAtWallProb'] = x
    # Adds the run to the database, makes the macro, 
    # syncs it to Optima server, and runs it on Optima
    srkdata.make_and_run(s,r,"optima") 
    time.sleep(2) # To ensure random seeds will be different

Sync results files based on Run ID number, analyze them, and add summary information to the database.

rids=range(7610,7614)
for rid in rids:
	srkdata.calc_run_stats_to_database(rid)

The following, in a Jupyter notebook, produces a plot from data from the database:

%matplotlib inline
import srkdata
import matplotlib.pyplot as plt
from pylab import rcParams
srkglobal.set_computer("work_laptop")

# Plot Settings
variable = 'TimeLimit'
plot_type="PhiQGaussianQ"
main_title = ''
x_axis_title = r'Precession time (s)'
y_axis_title=r'$q$'
titles=[main_title,x_axis_title,y_axis_title]

lines = [range(7367,7372),range(7480,7485),range(7379,7385),range(7373,7378)]
legend_titles=[r"$E_0= 1\,\frac{MV}{m}$",
               r"$E_0= 100\,\frac{MV}{m}$",
               r"$\partial B /\partial z=1\,\frac{pT}{cm}$",
               r"$\partial B /\partial z=1\,\frac{nT}{cm}$"]
config_type='Par'

# Graphics Settings
plt.rc('font', family='sans-serif') 
plt.rc('font', serif='Arial')
rcParams['figure.figsize'] = 10, 5
rcParams['xtick.labelsize'] = 22
rcParams['ytick.labelsize'] = 22
colors=['deepskyblue','limegreen','hotpink','r']
markers = ['d', 'o', 'v', '^']
fig1 = plt.figure(figsize=[10,5])
ax = fig1.add_subplot(1, 1, 1)


# Get data and plot lines
full_plot_type=config_type + "_" +plot_type
data=[]
for i in range(len(lines)):
    data = srkdata.get_plot_data_from_database_mult([lines[i]], [variable,full_plot_type])
    x,y= [data[0][j] for j in range(len(data[0]))]
    marker_size=13
    if i == 0:
        marker_size=15
    plt.plot(x, y,label = legend_titles[i],color=colors[i],linestyle="-",markeredgecolor="black",markeredgewidth=1.0,marker=markers[i],ms=marker_size)

#Other graphics settings
plt.axis([ 0, 105,.95,1.79])
plt.tick_params(labelsize=22,length=13)
plt.tick_params('both', length=15, width=1, which='major')
plt.tick_params('both', length=7, width=1, which='minor')
plt.xlabel(titles[1], fontsize=22)
plt.ylabel(titles[2], fontsize=26)
plt.title(titles[0], fontsize=22)
plt.grid(True)
plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3,
           ncol=2, mode="expand", borderaxespad=0., fontsize=26,numpoints=1)
plt.savefig(srkglobal.graphs_dir+"Fig3Test.png", bbox_inches='tight', dpi=100)
plt.show()