G2p Beampackage

From Hall A Wiki
Revision as of 11:46, 10 June 2014 by Pzhu (Talk | contribs)

Jump to: navigation, search

Feature

g2p beampackage is a python package developed for position calculation, it contains the package for:

  • Harp data analysis from raw harp data
  • BPM calibration
  • Raster calibration and reconstruction
  • Decode bpm information from rootfile
  • Calculate position and dump to pickle file
  • Insert position to rootfile
  • Read run information, including:
    • BPM calibration constant
    • BCM calibration constant
    • Any run information saved in sqlite database which synced with Ryan's Mysql database plus some additional BPM information

Also it includes several small tools to let life easier.

Download and install

There have two parts for the beampackage, source code and database. You can copy them from the g2p work disk:/w/halla-sfs62/g2p/centos62/g2ppylib Once you copied it, you need to set the environments below:

  • REPLAY_OUT_PATH used to find your rootfile
  • BEAMPACPATH location for beampackage source code directory
  • BEAMDBPATH location for beampackage database directory
  • BEAMPKLPATH The position to save your pickle file, if there is corresponding pkl file exists beampackage will read it directly and skip decode or calculate
  • BEAMPKLBAK The position to save your pickle files which you don't want to redecode or recalculate and you want stay it as stable version, beampackage will check BEAMPKLPATH first then check BEAMPKLBAK
  • BEAMDEBUG debug bit, used to set 0
  • BEAMUPDATE automatically update beampackage, you can set to 0 to close it
  • BEAMUPDATECHECK check beampackage updated, you can set to 0 to close it
  • PYTHONPATH you need to add your BEAMPACPATH to PYTHONPATH

To use the beampackage, you need to make sure the package following is installed:

  • python 2.7
  • root with python module compiled from cern
  • scipy,numpy and matplotlib

The following modules should be came with python and you don't need to install any more: "sys","os","urllib","urllib2","socket","re","threading","math","pickle","shutil","glob","array","time","linecache","zipfile","ctypes","xml.etree.ElementTree","select","bisect","gc","multiprocessing"

Database

There are several type of databases you can find in BEAMDBPATH directory, ascii txt database, ods file, c code, pkl file and sqlite database

  • sqlite database
    • g2p.db is converted from Ryan's mysql database, and added some additional BPM information
  • c code
    • bpm_$1_$2.c are pure c code, they are fitted function used to transport the positions from two BPMs to target(x_a,y_a,x_b,y_b -> x_tgt,y_tgt,theta_tgt,phi_tgt) when there is target magnet field exists. The Makefile is also exists in the database directory used to compile them. Those functions are fitted by using BdL method and mudifi fit program, you can find them in g2p work disk: /w/halla-sfs62/g2p/pzhu/work/beamDrift, you need to install root and clhep and gcc,fortran before using it. $1 is the beam orbit which you can find from sqlite database and $2 is the integered target z position.
  • ascii file the normal ascii txt file, you can edit it by any txt editor
    • bpma/b_$run$.dat are the bpm calibration constants files. a/b shows which bpm it used, run number in filename is just a tag came from one of the bpm calibration run, it used to check which arm is available. The constant file contains the available run period info, available target z position info, bpm calibration constant information
    • raster_$run$.dat are the raster calibration constants files. The avail run period info, avail target z info, raster calibration constant are included in the file. run number in filename is just a tag same as bpm calibration constant file. They used to transfer the raster magnet current information to position offset caused by raster, which used to get the event by event position at target.
    • beampackage.conf defined several beampackage settings.
    • bpmerr.conf contains the bpm and harp survey information
    • bpmcalib.conf contains several special calibration settings for each calibration period
  • ods file the OpenDocument Spreadsheet file, you can open it by using openoffice or libreoffice
    • bcm calibration.ods saved bcm calibration constants for each periods, each devices, each arms
    • harppeaks.ods contains harp peak informations from raw harp data and bpm calibration informations for each period, and the event cuts informations for the bpm calibration runs
    • period.ods the beamline period during experiment. You can find same information from g2p.db
  • pkl file dumped from pickle module in python, you can load it in python code to reconstruct to a original python object structure
    • runcurr.pdt Beam current for each run, mixed to g2p.db
    • pedgain.pdt pedestals for two gains both from 0 to 40, div from 0 to 4, fitted from noise study at the end of run
    • bpmraws.pdt contains the average bpm raw ADC value for each run
    • pedestal_hap.pdt the pedestal values for a lot of runs for happex ADC. mixed to g2p.db
    • positions.pdt average position for each run, mixed to g2p.db
    • posrms.pdt position uncertainty for each run, mixed to g2p.db

Source code

The beampackage is built by using python 2.7, also includes several c functions in order to improve the efficiency by using ctypes.

  • signalfilter.py This file contains several functions and classes, the main purpose of it is decode the bpm information from rootfile, add the software filter to the raw ADC signal, calculate the current from raw, judge the beam move. Also include the function to calculate position from raw.
  • bpminsert.py The main purpose of this file is used to insert the bpm information to existed rootfile's "T" tree, calculate the positions at bpms and target. Also include the function to calculate the position at target from two bpms.
  • bpmcalib.py This file provides the class to calibrate bpm, combine with "bpmfit.py"
  • bpmfit.py This file is used to do the fit for bpm calibration
  • harppos.py This file gives the classes and functions to calculate the beam position from harp peaks, and transfer it to several coordinates and transport the position to bpm.
  • harppeak.py This file is used to automatically find the harp peak from raw harp datas and save it to rootfile
  • rasterrecon.py This file is used to calibrate rasters, and reconstruct the raster shape.
  • pacupdate.py This file is used to update the beampackage from wiki by using urllib2
  • runinfo.py This file provides a class to read a lot of run informations from database, it also provides an api to access sqlite database.