2A. Analyzing your data with "ana"

Getting names for available fields

This will by list all the available fields:

SDAna In: ana.Keys()

You can pass a string and only field names that match the string will be listed. ana.Keys2d() will list only images (2-d arrays).

Looking at variables (1d and 2d plots)

Usage: SDAna In: ana.plotVar(varname)

This function will make a plot of the variable varname which can be a string containing the key-name or a list of strings for 2-d data. You can apply cuts (applyCuts='SelectionName'), set cuts by clicking on the figure (setCuts=True)You can specify an ROI to reduce multi-dimensional data. asHist=True will produce a 2-d histogram rather than a scatter plot when supplying two input variables.

ipm2 plot

LDana In [3]: ana.plotVar?

Type: instancemethod

String form: <bound method LittleDataAna.plotVar of <LittleDataAna.LittleDataAna object at 0x7f87edbed410>>

File: /reg/d/psdm/xpp/xpptut15/res/littleData/xppmodules/scripts/LittleDataAna.py

Definition: ana.plotVar(self, plotvar, numBin=[100], setCuts=None, applyCuts=None, limits=[1, 99], fig=None, asHist=False)

Docstring: <no docstring>

LDana In [4]: ipm2plot = ana.plotVar('ipm2/sum')

plot ipm2/sum from 0.000150301 to 1.00656

Filters - Event Selection

With a noisy source as the FEL, it is very important to select the events you would like to use for your analysis. For this, the ana object has the concept of "selections". Upon start, a "def" selection is created that required that event have both X-ray and optical laser present. You can admire stringent requirements to this selection and/or create different "pots" of events: e.g. laser-off event or magnet on/off selections. You add new requirements to an event selection like this:

LDAna In: ana.addCut('ipm2/sum',0.05,10.,'on')

This add a requirement of a minimal X-ray intensity to a bucket of events called "on". Should the Selection "on" not exist yet, it will be created. Cuts can be added as described above or you can specify "setCuts=<selectionName>" in the ana.plotVar() method: this will allow you to click on the plot to select events for both 1-d or 2-d plots.

You can then specify "applyCuts=<selectionName>" for both plotVar and plotScan and only events passing the requirements will be used. This is illustrated here:

Selection

LDana In [10]: ana.addCut('lightStatus/xray',0.5,1.5,'on')

LDana In [11]: ana.addCut('lightStatus/laser',0.5,1.5,'on')

LDana In [12]: ana.addCut('ipm2/sum',0.05,10.,'on')

LDana In [13]: ana.addCut('tt/FLTPOSFWHM',90.,120.,'on')

LDana In [14]: ana.printCuts('on')

Cut 0: 0.500000 < lightStatus/xray < 1.500000

Cut 1: 0.500000 < lightStatus/laser < 1.500000

Cut 2: 0.050000 < ipm2/sum < 10.000000

Cut 3: 90.000000 < tt/FLTPOSFWHM < 120.000000

LDana In [15]: fig = plt.figure(figsize=(8,5))

LDana In [16]: pos = ana.plotVar('ipm3/sum',fig=fig)

plot tt/FLTPOS from 0 to 722.58

LDana In [17]: posCut = ana.plotVar('ipm3/sum',fig=fig,applyCuts='on')

plot tt/FLTPOS from 291.069 to 505.09

Looking at the scan (1-d only)

This function will make the plot you are most likely interested in (the signal variable for selected events, normalized as a functions of the scan-variable). It will either use the scan steps or, in the case of a delay scan, the delay with timetool correction in which case you should specify the number of bins to be used (numBins=100),the bin size of pass the bins to be used. plotScan can return a dictionary that can be used to overlay different signal or signal for different event selections.

LDAna In: cspadScan=ana.plotScan(i0=['ipm3/channels',[1,4]],sig='cs140_rob/ROI_sum',ttCorr=True,applyCuts='def',Bins=np.arange(0.5,1.8,0.02))

Example Data available at SLAC:

The data used for the figures above is available in the "experiment" xpptut15 to anybody with a SLAC account. The "ftc" folder contains littleData files. At this moment, they are being updated. Runs 251 and 252 are very recent examples for our new type of delay scan for an analysis using a diode as well as a cs140 for the signal.

/reg/d/xpp/xpptut15/res/littleData contains the setup for production of these files and scripts that demonstrate the analysis. You can run these in that directory calling: ./runLittleDataAna_tutorial -r 251 or ./runLittleDataAna_tutorial -r 252.

The code making the example plots can be found in xppmodules/scripts/LoadLittleDataAna_tutorial.py

/reg/d/xpp/xpptut15/res/littleData/xppmodules/scripts/DelayScan.py

is a standalone version of this script which could be used as bases for user written code in case the "ana" setup is too restrictive.