Motivation

Development of this application was stimulated by the discussion with Marcin Sikorski (meeting on 2012-08-30), doing xcs experiments.
Users need in real-time algorithm for calculation of image vs time auto-correlation function

g2(tau) = <I(t)*I(t+tau)> / (<I(t)> * <I(t+tau)>),

where I(t) is an image intensity at time t, and tau is a delay between two measurements.
Typical experimental condition can be described as follows:

Algorithm

Basic idea is (1) to split image vs time for small parts in image, (2) to process each part on separate computer node, (3) to merge results at the end of processing. It is clear that significant speedup (about T/N_nodes_) is achieved at the 2nd stage. These three stages are performed in separate C++ applications. Wrapping python script allows to submit job by a single command. It takes care about file and sub-process management in this job, as described below.

Code location

All modules for this application resides in the package ImgAlgos:

Module

Functionality

ImgVsTimeSplitInFiles

splitter

CorAna

base class with common methods

CorAnaData

data processing for split files

CorAnaInputParameters

provides storage for input parameters

CorAnaMergeFiles

merging algorithm

CorAnaProcResults

Example showing how to access results using C++ and produce a table for presentation

CorAnaPars.py

singleton class for parameter storage in the wrapping file manager

CorAnaSubmit.py

global methods for the file manager

app/corana_submit

pythonic script which defines the sequence of procedures

app/corana.cpp

main module for the part of image vs time correlation processing

app/corana_merge.cpp

main module for merging

app/corana_procres.cpp

main module for processing of results from correlator array

data/psana-corana.cfg

psana configuration file for ImgVsTimeSplitInFiles

data/PlotCorAnaResults.py

example of the python script which plots the resulting graphics

Image splitting

Image splitting is implemented as a regular psana module ImgAlgos::ImgVsTimeSplitInFiles.

Command to run interactively on psana#### or submit in batch from pslogin## node:

psana -c <config-file> <xtc-file-list>
bsub -q psfehq -o log-file 'psana -c <config-file> <xtc-file-list>'

For example:

psana -c ImgAlgos/data/psana-corana.cfg  /reg/d/psdm/XCS/xcsi0112/xtc/e167-r0015-*

where ImgAlgos/data/psana-corana.cfg is an example of the configuration script for psana and /reg/d/psdm/XCS/xcsi0112/xtc/e167-r0015-* are the input xtc files for particular run.

A couple of limitations due to LCLS policy:
Interactive job can be run on psana#### computer, but the batch queues are not seen from psana#### nodes...
Batch job can be submitted from pslogin## computer, but data are not seen directly from pslogin## nodes...

Produces the files:

cor-ana-r0015-b0000.bin - file with a part of image vs time
cor-ana-r0015-b0001.bin
cor-ana-r0015-b0002.bin
cor-ana-r0015-b0003.bin
cor-ana-r0015-b0004.bin
cor-ana-r0015-b0005.bin
cor-ana-r0015-b0006.bin
cor-ana-r0015-b0007.bin
cor-ana-r0015-time.txt - list of time-records for all events in processed run.
cor-ana-r0015-time-ind.txt - list of time-records for all events in processed run with time index.
cor-ana-r0015-med.txt - file with metadata. In particular it has the original image size, number of image parts for splitting, number of images in run, etc.

Algorithms:

This approach allows to apply the modest event selection algorithms in psana pre-processing stage.
But, it still based on uniform time indexing...
Q: Is it really good assumption for this kind of experiments?

Time correlation processing

ImgAlgos/app/corana application

Command to run interactively on psana#### or submit in batch from pslogin## node:

corana -f <fname-data> [-t <fname-tau>] [-l <logfile>] [-h]
bsub -q psfehq -o log-file 'corana -f <fname-data> [-t <fname-tau>] [-l <logfile>] [-h]'

For example the interactive and batch mode commands:

corana -f cor-ana-r0015-b0001.bin -t my-tau.txt
bsub -q psfehq -o log-file 'corana -f cor-ana-r0015-b0000.bin'

Produce files:

cor-ana-r0015-tau.txt          - string of {{tau}} values for which the auto-correlation function is evaluated
cor-ana-r0015-b0000-result.bin - auto-correlators for the part of the image for all {{tau}} values
cor-ana-r0015-b0001-result.bin
cor-ana-r0015-b0002-result.bin
cor-ana-r0015-b0003-result.bin
cor-ana-r0015-b0004-result.bin
cor-ana-r0015-b0005-result.bin
cor-ana-r0015-b0006-result.bin
cor-ana-r0015-b0007-result.bin

Merging results

ImgAlgos/app/corana_merge application

Command to run interactively on psana#### or submit in batch from pslogin## node:

corana_merge -f <fname-data> [-t <fname-tau>] [-l <logfile>] [-h]
bsub -q psfehq -o log-file 'corana_merge -f <fname-data> [-t <fname-tau>] [-l <logfile>] [-h]'

For example:

corana_merge -f cor-ana-r0015-b0001-result.bin -t my-tau.txt

This procedure produces file:

cor-ana-r0015-image-result.bin

Example of how to get and process results

ImgAlgos/app/corana_procres

Command to run interactively on psana#### or submit in batch from pslogin## node:

corana_procres -f <fname-data> [-t <fname-tau>] [-l <logfile>] [-h]
bsub -q psfehq -o log-file 'corana_procres -f <fname-data> [-t <fname-tau>] [-l <logfile>] [-h]'

Basically it reads files with results and produces the histogram-like table *-hist.txt.

Automatic processing

ImgAlgos/app/corana_submit - is a wrapping script which allows to run all of above procedures by a single command from pslogin## node and it keeps eye on processing of jobs in batch and doing the file management. Command to start:

corana_submit [-c <config-file>] [-t <fname-tau>] [-x] <xtc-file-list>

For example:

corana_submit -c ImgAlgos/data/psana-corana.cfg -t my-tau.txt /reg/d/psdm/XCS/xcsi0112/xtc/e167-r0015-s00-c00.xtc

This script sequentially performs operations for single run as follows:

  1. Initialize all parameters
  2. Run psana to split image for files
  3. Check that all split files are produced
  4. Submit job for time-correlation processing
  5. Check that all processed files are produced
  6. Submit job for merging
  7. Check that merged file is produced
  8. Submit job for test processing of the file with results
  9. List all created files
  10. Clean-up files in the work directory
  11. List of preserved files

    The next to last procedure deletes all intermediate split- and log- files.
    In debugging mode this procedure may be turned off.

Manual sequential processing

In case of manual processing of all scripts, commands need to be issued in a right order. Commands corana, corana_merge, and corana_procres should have the same list of parameters. This is important, because all file names for these procedures are generated by the same base class ImgAlgos/src/CorAna.cpp

Right sequence of commands to run interactively on psana####

psana -c <config-file> <xtc-file-list>
corana         -f <fname-data> [-t <fname-tau>] [-l <logfile>] [-h]
corana_merge   -f <fname-data> [-t <fname-tau>] [-l <logfile>] [-h]
corana_procres -f <fname-data> [-t <fname-tau>] [-l <logfile>] [-h]

or submit in batch from pslogin## node:

bsub -q psfehq -o log-file 'psana -c <config-file> <xtc-file-list>'
bsub -q psfehq -o log-file 'corana         -f <fname-data> [-t <fname-tau>] [-l <logfile>] [-h]'
bsub -q psfehq -o log-file 'corana_merge   -f <fname-data> [-t <fname-tau>] [-l <logfile>] [-h]'
bsub -q psfehq -o log-file 'corana_procres -f <fname-data> [-t <fname-tau>] [-l <logfile>] [-h]'

The corana batch jobs can be submitted and run on separate butch nodes in parallel. All other procedures can be submitted when previous is successfully finished and all necessary files are produced.
The corana_procres command is optional and is currently used for test purpose only. But, it may be replaced by real analysis code.

File formats

Quick start guide

We assume that everything is set up to work on LCLS analysis farm, otherwise see Computing (including Analysis) and Account Setup.

How to run this procedure

If the version of the package ImgAlgos is available as a current software release, then you may run the script command(s) directly, for example:

cd <your-favorite-directory>
mkdir work_corana
sit_setup
corana_submit [-c <config-file>] [-t <fname-tau>] [-x] <xtc-file-list>

If the code in the package ImgAlgos has been recently changed and the updated release is not yet available, then one need to create the local release directory, get the latest/HEAD version of the package, and compile the code as shown below:

cd <your-favorite-directory>
newrel ana-current myReleaseDirectory
cd myReleaseDirectory
sit_setup
addpkg ImgAlgos HEAD
scons

Where to find results

The procedure will produce a bunch of files in the work_corana directory. If everything is OK, then all spit - and log- files will be removed at the end of automatic corana_submit procedure. The most important files are preserved for further analysis:

File name tail

Format

Content

*-image-result.bin

binary for <float>

correlators for all image pixels for all tau values

*-time-ind.txt

text

time records for all selected events/images

*-tau.txt

text

the list of tau intervals

*-med.txt

text

meta data parameters

*-hist.txt

text

Histogram array with correlators averaged for ring regions of the image for all tau values, shown in the first column

How to look at results

It is assumed that all files listed in previous section may be used for further analysis, depending on particular goals. The optional script corana_procres is designed as an example of how to access data from C++ code. Class CorAnaProcResults produces the file *-hist.txt
A simple python script shows how to plot this file:

./ImgAlgos/data/PlotCorAnaResults.py work_corana/cor-ana-r0015-hist.txt

Another option is to use python script for direct processing of the resulting files.
This is not elaborated yet.
Q: What kind of further processing is desired and what tools are going to be used?