Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepython
# these first two lines for example purposes only, to allow user to write
# calibration information to local directory called "calib"
# should be deleted for real analysis.
import psana
psana.setOption('psana.calib-dir','calib')
from xtcav.DarkBackground import *

DarkBackground(experiment='xpptut15', 
	run_number='300',   # run number within experiment
	max_shots=1000,		# maximum number of shots to process
	validity_range=(300,302))  # range of runs for which this dark run should be used

An example of a non-lasing run is in /reg/g/psdm/tutorials/examplePython/xtcav/xtcavLasingOff.pySample of "no-lasing" reference generating script:

Code Block
languagepython
# these two lines for example purposes only, to allow user to write
# calibration information to local directory called "calib"
# should be deleted for real analysis.
import psana
psana.setOption('psana.calib-dir','calib')
from xtcav.GenerateLasingOffReferenceLasingOffReference import *
GLOC=GenerateLasingOffReferenceLasingOffReference();
GLOC.	experiment='xpptut15'
GLOC.runs,
	run_number='301'
GLOC.maxshots=1400
GLOC.nb=1
GLOC.islandsplitmethod = 'scipyLabel'       # see confluence documentation for how to set this parameter
GLOC.groupsize=40             # see confluence documentation for how to set this parameter
GLOC.SetValidityRange(300,302) # delete second run number argument,
	max_shots=200,
	num_bunches=1,
	validity_range=(301,)) #only give first run number to have the validity range be open-ended ("end")
GLOC.Generate();

This script can be quite slow.  It can be easily run in parallel by submitting a parallel MPI job to the batch system as described here.  Note that if you analyze multiple runs, you must call GLOC=GenerateLasingOffReference() once per run to get the correct constants. Once the dark/lasing-off analysis has been completed, users can analyze the lasing-on events using a standard psana-python script similar to the one below.

...

Code Block
languagepython
from psana import *
import matplotlib.pyplot as plt
from xtcav.ShotToShotCharacterizationLasingOnCharacterization import *
dsexperiment =DataSource( 'exp=xpptut15:'
run = '302:smd')
XTCAVRetrieval=ShotToShotCharacterization();
XTCAVRetrieval.SetEnv(ds.env())
import matplotlib.pyplot as pltmode = 'smd'
ds = psana.DataSource("exp=%s:run=%s:%s" % (experiment, run, mode))
ngood = 0
XTCAVRetrieval=LasingOnCharacterization() 
for evt in ds.events():
    if not XTCAVRetrieval.SetCurrentEventprocessEvent(evt): continue
    time,power,ok=XTCAVRetrieval.XRayPower()  
    if not ok: continue
 # continue  agreement,ok=XTCAVRetrieval.ReconstructionAgreement()
    if not ok: continue
    ngood += 1to next image if analysis fails for some reason
    # time and power are lists, with each entry corresponding to
    # a bunch number.  The number of bunches is set by the GLOC.nb
    # parameter in the lasing-off analysis.  In general, one should
    # also cut on the "agreement" value, which measures the agreement
    # between the first and second moment analysis (larger is better).
    time, power = XTCAVRetrieval.xRayPower(method='RMS')  
    agreement = XTCAVRetrieval.reconstructionAgreement()
    ngood += 1
    print 'Agreement: %g%% ' % (agreement*100)
    plt.plot(time[0],power[0])
    plt.xlabel('Time (fs)')
    plt.ylabel('Lasing Power (GW)')
    plt.title('Agreement %4.2f'%agreement)
    plt.show()
    if ngood > ngood>11: break
        break

Notes: The LasingOnCharacerization module uses the detector interface to find the datasource being used. The program will fail if you try to process events without first setting a datasource. If you are analyzing an older experiment, you may find that psana does not support the 'smd' mode. Instead, use the 'idx' modeThis script runs on one core, but it can be MPI-parallelized in the standard psana-python manner described here.

One caveat: this data shows "horns" at the beginning and the end of the bunch which confuse the algorithm (the accelerator often behaves in this manner).  Only the middle peak in the plotted spectrum is the relevant lasing peak.

Some tips for lasing-on analysis:

  • Look at the distribution of the "agreement" parameter that is returned by the ReconstructionAgreement() method.  This value represents the "dot product" of the power-spectrum from the first-moment-analysis The second-moment analysis (energy spread method) of the XTCAV image with the power-spectrum from the second-moment-analysis generally provides a better estimate of the true power profile of the XTCAV image.   Only believe the data where the agreement is good (in the past >0.5 has been useful for some analyses)It is recommended that you use method='RMS' when calling xRayPower(), as demonstrated above.
  • Ignore shots where the X-ray intensity is low, but cutting on the FEEGasDetector value to select stronger shots

...

Close the existing plot window to show the plots for the next event.  If you want to modify the 105-line "xtcavDisp" python script (e.g. to change which events are displayed) you can find it in  /reg/g/psdm/sw/releases/ana-current/xtcav/src/xtcavDisp.

 

How Often to Take a Lasing Off Run

(courtesy of Tim Maxwell)

...

  

XTCAV Analysis Parameters

-num_bunches

Lasing-off Analysis Parameters

(courtesy of Alvaro Sanchez-Gonzalez)

-NB: Number of bunches: typically 1, but sometimes can be 2+ for some LCLS experiments.  Just as a note for the future, if at some point you want to do two bunch partial reconstruction (i.e. without lasing off reference), you will need to specify explicitly the number of bunches in an undocumented way (i.e. changing an attribute without a get/set method. Example:

XTCAVRetrieval=ShotToShotCharacterization();
XTCAVRetrieval.SetDataSource(dataSource)
XTCAVRetrieval._nb=2
If you do this, but then it happens that there is a reference available, 
and the number of bunches is different, it will take the number of 
bunches in the reference file.

For analysis of a lasing on run, this must be the same as the number of bunches in the reference lasing off run that you're using.

-maxshots: number of images to process for dark background or lasing off reference generation. In -n: number of images: in principle the bigger the better, but around 1400 used to 1000 should work fine. If you select a bigger number for dark background generation, then you should get a more representative average of the background noise.  If you select a bigger number for lasing off reference generation, you will get more references, but it . This will also take longer to find the right reference shot to shot.process but you'll have a better chance of finding a well matched profile when processing lasing on shots. 

-num_groups: The number of groups into which lasing off profiles are clustered. Setting this number to 1 would be -groupsize: 5 is a good number. Increasing this number will make better references, but they may also make them less accurate, as you would be averaging a larger number of profiles. If you decide to increase this number by a factor, then I would also increase n by the same factor, so in the end the total number of reference is the same. (see also thoughts from Tim Maxwell below).

...