How to run pattgen to generate patterns

This is an example of pattern generation for a single wedge, B2W3.

To run the program from a different account/computer, you need to copy the following directories:

/cdf/home/carosi/svt_config
/cdf/home/carosi/patterns_2002dec13
which contain the code and the input files. In particular:
/cdf/home/carosi/svt_config/source
contains the source code;
/cdf/home/carosi/svt_config/data
contains the standard input files, which are not to be changed (geometry, detector description,...);
/cdf/home/carosi/patterns_2002dec13
contains the example input files.

In this example you want to change the layer map from 0123 to 0134 for B2W3.

The first step is to compile the program. In this example we work in the directory ~carosi. Also, we work on a linux machine. This program has problems running on SGI.

To compile the program, just do the following:

cd ~carosi/svt_config/source/pattgen
./pattgen_make
rm *.o

Now there should be a file pattgen.exe.

Next step: prepare the input files. A detailed description of the input files ("high level files") can be found in http://www.pi.infn.it/~punzi/SVT_config.html

Now we create a directory to collect the input files, and we copy some reference files:

cd
(we go back to the home directory, ~carosi on fcdfsgi2)
mkdir patterns_2002dec14
ls ../patterns_2002dec13
cp ../patterns_2002dec13/offline_100030_20021213000000mapset .
mv offline_100030_20021213000000.mapset offline_100030_20021214000000.mapset 
cp ../patterns_2002dec13/pattgen_w03.in .

For now, the only input file is

pattgen_w03.in
. This is the input file for wedge 3. When we want to generate patterns for a single wedge, we have to do that for the whole barrel. The mapset file will be needed later.

First, we change the layer map for barrel 2. So, we change the line

PLANE_NUMBERS2    0111101  (1 - the plane is on, 0 - is off )
to
PLANE_NUMBERS2    0110111  (1 - the plane is on, 0 - is off )

The other input file is the superstrip files (we still have to prepare it). First, we have to decide the name for the superstrip file. It is a good thing to include the date in the name. So we change the corresponding line as following:

SS_FILE          /cdf/home/carosi/svt_config/data/w03_021214.ss

Next, the output file:

PATT_FILE3       patt_021214_w03.patt
Note that since we want to generate patterns for wedge 3, we use the keyword PATT_FILE3. If we use additional keywords for other wedges, the program complains.

Also, we need the empty5.patt files at the end.

We want to be sure that the patterns are centered around a point which is close enough to the real beam position

XVERT            -0.2010
YVERT             0.3917
It is ok, we don't change it.

The next step is the preparation of the superstrip file. This can be done by running a python script:

python ~/svt_config/source/wss1.py  pattgen_w03.in
X012X35|XX01235|X0123X5|X0123X5|X0123X5|X0X1235

mv ss.out w03_021214.ss
cp w03_021214.ss ~carosi/svt_config/data/
The script requires the pattgen input file pattgen_w03.inas argument. The output is the file ss.out, which has to be renamed and copied. Also, it prints a string on the terminal output. Such a string is the layer map for wedge 3 in the format used by the mapset file, so we paste it directly into the file.

Before running the program, we can change the mapset file:

emacs offline_100030_20021214000000.mapset

First we have to change the line containing the name of the mapset file:

mapsetName offline_100030_20021213000000.mapset

Then the entries for wedge 3, so we change the following lines from

w03_layerMap	X012X35|XX01235|X0123X5|X0123X5|X0123X5|X0X1235
w03_pattFile    patt_021213a_w03.patt
w03_ssFile      w03_021213a.ss
to
w03_layerMap	X012X35|XX01235|X01X235|X0123X5|X0123X5|X0X1235
w03_pattFile    patt_021214_w03.patt
w03_ssFile      w03_021214.ss
The numbering of the layers is a bit different from before. The barrels are separated by a '|'. The first character is for layer 00, then 5 SVX layers, then the XFT layers, which is always 5. 'X' means 'not used'. The active layers are numbered from 0 to 3.

Now we run pattgen:

~carosi/svt_config/source/pattgen/pattgen.exe < pattgen_w03.in 
and that's it.

How to run pattgen to generate patterns in 4-out-of-5 mode

This is an example of pattern generation for all the wedges, in "4-out-of-5" mode. It is easier than in "4-out-of-4" mode.

We start by copying the previous pattern directory

cp -r /cdf/home/carosi/patt5l_030825 patt5l_031206
cd patt5l_031206
rm *.patt
Now we change the input file pattgen_12345F.in. We do not touch the fields PLANE_NUMBERS. The "4-out-of-5" mode for the patterns is indeed a "5-out-of-5" mode, all the layers are set to 1 (except layer 00).

We do not touch the field for the superstrip file (SS_FILE, because it is always the same. Of course, we can change the name.

Since we want to generate patterns for all the wedges we have to check the following fields:

WEDGE_MIN 0
WEDGE_MAX 11
Next, we have to modify the names of the output (patterns) files:
PATT_FILE0       patt_12345F_031206_w00.patt
PATT_FILE1       patt_12345F_031206_w01.patt
........
Last, the beam position:
XVERT            -0.1950
YVERT             0.5900
ZVERT            0.0
XSLOPE           0.000715
YSLOPE           0.000396
Notice that now there are two new fields, the beam slopes in X and Y, in radians. Now we are ready to start:
~carosi/svt_config/source/pattgen/pattgen.exe < pattgen_12345F.in

Once we have the new patterns, we have to modify the mapset file. First we rename it as

4outof5_20031206000000.mapset
We change the first line to
mapsetCrc 0
and the second line to
mapsetName 4outof5_20031206000000.mapset
(it must be the name of the file).

We have to add a comment like this to explain what we are going to chenge:

# 2003-12-06 RC: new fcon and new patterns for 4-out-of-5
#                (x=-0.1950,y=0.5900,mx=0.000715,my=0.000396)

There is a new line to modify, patternCenter:

patternCenter   -1950|5900|715|396|1200
The numbers are the X and Y positions of the beam in micron, the X and Y slopes in microradians, and the beam spot radius in micron. The latter is always 1200 and should never change.

Now, in the 12 wedges, we change the names of the patterns files, to

patt_12345F_031206_w00.patt
and so on.

How to check pattern coverage

We can use pattgen to check the pattern coverage (geometrical acceptance) of the new patterns.

We are still in the directory patt5l_031206. We have to check the file patteff.dat. This file is similar to pattgen_12345F.in, but there are some important differences. There is a new field:

EFF_FILE         eff.dat
which is the output file containing data to calculate the pattern coverage. The output files for the patterns are
PATT_FILE0       /dev/null
PATT_FILE1       /dev/null
....
and so on, since we do not want to generate new patterns. The beam position can be different from the one used in pattgen_12345F.in. In fact, we may want to che the pattern coverage when the beam is displaced with respect to the center of the patterns, or it has a different slope.

In the same way, PTMIN can be different (the normal value is 2) if we want to check the coverage for different PT thresholds.

Again, it is useful to check the coverage at large values of the impact parameters, so we should use

SPOTR            0.2
i.e., we use tracks in a 2 mm radius from the center.

The number of tracks is given by

NTRACKS          100000
(usually 100000 tracks are enough).

The last fields are pattern input files:

PATTERN_banks   12
12 AM banks
       patt_12345F_031206_w00.patt
       patt_12345F_031206_w01.patt
  .........
and so on.

Now we are ready to run the program

~carosi/svt_config/source/pattgen/pattgen.exe < patteff.in

When the program has finished, we modify the file patteff.kumac in the following lines:

alias/crea x0 (-0.195)
alias/crea y0 (0.590)
(they must be th same values used in patteff.in, for the correct calculation of the impact parameter.

Next we do the following:

paw
and
exec patteff
to create an ntuple, then
exec patteffplots
to create sample plots for the coverage versus wedge number, PT, impact parameter, and phi.

How to check patterns with SVTMon

The new patterns can be checked by running SVTMon with svtsim. In this example we do that on fcdfsgi2.

telnet fcdfsgi2

source ~cdfsoft/cdf2.cshrc
setup cdfsoft2 4.9.0

cd /cdf/data03/s7/off_val/carosi

newrel -t 4.9.0 testpatt

cd testpatt

addpkg -h SVTMon
cd SVTMon/src
gmake
gmake tbin

Now there is an executable in /cdf/data03/s7/off_val/SVTD_bank_monitor/SVTMon.exe

cd ../test

ls -lt /cdf/data08/look/aphysr/ | more

Now we have to edit the tcl file:

setup emacs
emacs SVTMon.tcl
First, we set the data file we want to read (in this example from the look area):
include file /cdf/data08/look/aphysr/ar025ee4.03a2phys
Then we have to change the parameter so that we run svtsim with SVTMon.
dataFileDir set ./svtsim/svtdata
This is the directory where the configuration files are copied from the database.
    Monitor_Mode set 2
That means we expect two SVTD banks, one for real data and one for svtsim data.
#path enable NoSimPath
#path disable WithSimPath
path disable NoSimPath
path enable WithSimPath
This is needed for svtsim.
ev begin
We read all the events.

Now we have to create the directory where the configuration files are copied from the database:

mkdir svtsim
mkdir svtsim/svtdata

Now we run SVTMon taking the configuration files from the database:

../../bin/IRIX6-KCC_4_0/SVTMon.exe	< SVTMon.tcl
We can abort the program after few events, when we are sure that the configuration files are copied.

We can check it:

ls svtsim/svtdata/

Now we copy the pattern file we have generated before:

cp ~/patterns_2002dec12/*.patt svtsim/svtdata
cp ~/patterns_2002dec12/*.ss svtsim/svtdata
cp ~/patterns_2002dec12/offline_100030_20021213000000.mapset  svtsim/svtdata
Nore that we need the suprestrip file and the mapset as well.

Also, we need to do the following:

ls svtsim/svtdata/*.hwset
svtsim/svtdata/20021213205301.hwset

cp svtsim/svtdata/20021213205301.hwset svtsim/svtdata/test.hwset
Now we change the tcl parameter in order to read files from svtsim/svtdata and not from the database:
emacs SVTMon.tcl
We change the following:
 useDB set f

 mapSet set offline_100030_20021213000000
 hwSet set test
And, finally, we run SVTMon:
../../bin/IRIX6-KCC_4_0/SVTMon.exe < SVTMon.tcl
After it is finished there should be the SVTMon ntuple, svtntuple_155364.hbook. A check can be done by comparing the svt parameters (c,d,f,chi2,...) with the svtsim parameters (sc,sd,sf,schi2,...). A typical check is the occupancy in each wedge (wd) and barrel (zin):
paw
PAW > h/file 1 svtntuple_155364.hbook
PAW > zone 1 2
PAW > n/pl 1.wd%zin ! ! ! ! box
PAW > n/pl 1.swd%szin ! ! ! ! box
PAW > 

How to generate constants with corrgen

In this example we generate fit constants for wedge 0, barrel 0, layer map 1234 (i.e. the first 4 SVX layers; 0 is the layer 00).

First we compile the program:

cd ~/svt_config/source/corrgen
corrgen_make
rm *.o
cd

We should have created the executable:

~/svt_config/source/corrgen/corrgen.exe

There is only one input file for corrgen:

cd ~carosi/fcon_021213
emacs corr1234F_test_z0.in
The format of the input file is very simple, and only few options have to be given. The layermap is in the same format as in the pattgen*.in file:
PLANE_NUMBERS:    0111101  (1 - if the plane is on, 0 - off )
The geometry input files are the following:
/cdf/home/carosi/svt_config/data/100030_1_GOOD_fixdbias.rgeo
/cdf/home/carosi/svt_config/data/svxii_official_b_7l.sreg
Then the name of the output file, without extention:
SVTFCON_FILE     1234F_test_021213
Since we want just one wedge
WEDGE_MIN        0
WEDGE_MAX        0
Then we can check the coordinates of the point (in the CDF reference frame) where the tracks are generated:
XVERT            -0.2219
YVERT            0.3847
which should be close enough to the real beam position.

The other options should not be changed.

Now, to run the program, just type

~/svt_config/source/corrgen/corrgen.exe < corr1234F_test_z0.in
The output file is 1234F_test_021213_w0z0.fcon. The format of this file is described in http://www.pi.infn.it/~punzi/gcon_v3.txt.

The other output file, 1234F_test_021213_o_w0z0.fcon, contains "orthogonalized fit constants", and is not needed.

In principle we are ready to run corrgen for all the wedges, all the barrels, all the possible 4-layer configurations.

For a given layer map and a give barrel, it is easy to generate the constants for all the wedges, just specify

WEDGE_MIN        0
WEDGE_MAX        11
in the input file.

Then, for the same barrel, we can generate the constants for all the 5 possible layer maps, we have just to change the PLANE_NUMBERS line. It is better to follow some naming convention for the input files. So, the file containing the line

PLANE_NUMBERS:    0111101  (1 - if the plane is on, 0 - off )
is called corr1234F_test_z0.in, the one containing
PLANE_NUMBERS:    0111011  (1 - if the plane is on, 0 - off )
is called corr1235F_test_z0.in, and so on.

The input files for the other barrels can be prepared in the same way. Just two things:

First, the wedge number must be given as (Barrel number)*12+(Wedge number) "sector number". For example, for barrel 1 we have tthe wedge numbers from 12 to 23.

The other thing is that XVERT and YVERT can be different from one barrel to another (in fact they are).

The name of the input files should contain the barrel number, e.g. corr1245F_test_z3.in for the 1245 layer map for barrel 3.

Now we have 30 input files, so we have to run the program 30 times. Each time 12 files will be produced, so the total we be 360 files. The files corresponding to the same sector should be appended together, since in the database there must be only 72 files, one for each wedge/barrel. A simple script, that can be used as an example to run the progam (once the 30 input files are ready) and put together the output files with a sensible naming convention, is vai.

Also, since the program takes about 30 hours to run for all the wedges, all the barrel, all the configurations, it may be reasonable to split it in independent parts and run it on different machines in parallel. As an example, parte1 and parte2 are the two parts in which vai is splitted con it can run on two machines in parallel.