How the Filter Package works:
-----------------------------
This event filter package is controlled by the rcp file
Jetefake.rcp

So to understand the parameters that control the output of this package it 
will be better to start with the rcp file. In the following I show the 
meaning of the rcp parameters as comments in the rcp file.
In the following 'emjet' means jets that have em fraction more than a certain
value (discussed later). One event should have at least one emjet to pass the 
selection criteria.
--------

// Author: Nirmalya Parua
//
// rcp for  Jetefake package
//

string PackageName = "Jetefake"


//     parameters for MC jet algorithm
float conesize   = 0.5     // cone size for the jets 
float ETseed     = 1.0     // Minimum E_T for the seed
float ETmin      = 5.0     // Minimum E_T of a jet
//
float minemfr    = 0.65    // Minimum emfraction of the jet. 
                           // Emfraction is defined as
                           // empt/jetpt. while calculating empt, pt of all 
                           // photons and electrons and any charged particle 
                           // with pt less than chargept (see second to last 
                           // parameter) are added.
                           
float minempt    = 10.0    // Minimum pt of emjet that are counted.

float maxemptclptfr = 10.0 // Ratio of the pt of the emjet to the 
                           // pt of the closest charged track to the center 
                           // of the jet ( in the code this ratio is called 
                           // ebyp) should be less than  maxemptclptfr
                          
float maxebyp       = 1.0  // ebyp of any jet ( not only em tagged jet) should
                           // be less than 'maxebyp'. putting a cut at 
                           // maxebyp=1 means not using this variable here.

float maxcldist  = 0.1     // maximum distance allowed for the closest 
                           // charged track from the center of the jet in the
                           // (eta, phi) space

float chargept   =1.0      // If pt of a charged track in a jet is less than
                           // 'chargept' (in GeV) then the pt of the charged 
                           // track should contribute to the empt of the 
                           // jet. 

int   needed     = 6000    // This is the number of events that you would like
                           // to be filtered out. So if the rejection factor
                           // is 30, you should generated about 180,000 events
                           // This package writes events till it reaches 
                           // the 'needed' number of good events (6000 here)
                           // Then although it keeps generating events but 
                           // don't write it any more. So one should put the 
                           // number of events to be generated at a 
                           // sufficiently high value so that 'needed' number 
                           // of events can selected.

-----
So in summary for an event to get selected it should have at least one emjet.
This emjet should satisfy 'maxcldist', 'maxemptclptfr', 'minempt' criteria.



A step by step guide to generate and simulate events for fake background study
-----------------------------------------------------------------------------
and then transfer those to SAM.
------------------------------

Introduction: In the following I give a step by step guide about how to
              produce monte carlo events at Lyon and then transfer those
              to sam at d0mino. Please don't feel hurt to see some 
              elementary unix commands in this guide. I found it easier to 
              write it that way.

1. Login to ccali

2. Go to the working directory.
   In this example 
   $ cd /afs/in2p3.fr/group/d0/prod-fake

3. If you want to make new executable for filter (fake) then do the
   Following

	i>$ setup D0RunII pmc02.01
       ii>$ setup d0cvs
      iii>$ newrel -t pmc02.01 generator (or some other name)
       iv>$ cd generator
        v>$ cp /afs/in2p3.fr/group/d0/prod-fake/genpmc0201/jetefake . 
       vi>$ cd include
      vii>$ gmake all

4. Make a directory from where to run the simulation job
   $ mkdir simulate

5. $ cd simulate

6. $ tar xvf $THRONG_DIR/info_data/pmc02/mc_runjob-new.tar
   
   This may change. If you have doubt please ask Michel and/or Evelyne
   about what tar file is the most updated one.

7. $ cd bin/Linux2-KCC_3_3/

8. Here you will see links to several executables.
   Put a link to your executable.
   For this example do
   ln -s  /afs/in2p3.fr/group/d0/prod-fake/genpmc0201/bin/Linux2-KCC_3_3/
          Jetefake_x Jetefake.x

9. Go to the template directory
   $cd ../../ mc_runjob/templates.
   
10. Edit the file generator_jobs.list to put your process
    (or if you don't need to change anything just copy it from
    /afs/in2p3.fr/group/d0/prod-fake/template/generator_jobs.list

   In this case I put the following line at the end of the file
   
   jetefake_cc    isajet         Jetefake.x  runJetefake Jetefake


   Here the first field jetefake_cc is the process, you can put any name but 
   this name will appear in the generated and simulated file names, so please 
   give a  meaningful name.

   The second field is the generator name, I put isajet as I am using this,
   if later you want to put other generators like pythia etc. please put that
   accordingly.

   The third name is the name of the executable. Please remember that this
   is the link that you put in the bin directory (described at point 6).
   
   Third field is the framework rcp file (without the filename extension).
   You can copy this from my area.

   The fourth field is any additional rcp files that you need. In this case 
   I put Jetefake. You have to copy this also from my area. I put enough
   comments there so that you will understand meaning of all parameters.


11. Also copy from /afs/in2p3.fr/group/d0/prod-fake/template into your 
    mc_runjob/templates , following files
    finish_gen.py
    import.py
    jetefake_cc.isa
    Jetefake.rcp
    runJetefake.rcp

    The .py files are needed to have correct file name. If you have original
    files then if you generate 200000 events and select only 6000 events
    then your filename will show 200000 events, but you would like 6000 there.
  
    jetefake_cc.isa is the isajet command file.

    Please remember to put the name same as the process.
    In this case the process name is jetefake_cc (see the discussion in point 
    10).

12. Also copy the file
    /afs/in2p3.fr/group/d0/prod-fake/template/MCinputWindow.py
    into
    mc_runjob/mc_runjob/
    directory.

13. The example above assumes that you want to filter out 6000 events, if you
    want to change this number to something else you need to edit following 
    files
 
    Jetefake.rcp  : there is a rcp parameter called needed, change this number
                    to the required number.

    MCinputWindow.py : change the number of events in the lines
                       number_filter_event = '6000evts.'
                       Please remember that this line appears several times.







How to Transfer files from ccali to sam (d0mino)
------------------------------------------------

There are good documentations at
http://d0-france.in2p3.fr/WORKING_GROUPS/SOFTWARE/MC_PROD/transfert.html
and at
http://d0ora2.fnal.gov/sam/doc/userdocs/SamRemoteDataGuide.html

In the following I give a step by step guide ( all these I got from
Evelyne Lebreton through e-mails)

1> Get write access to disks
   /sam/cache2/import
   /sam/cache1/import
   of d0mino from Lee Lueking (lueking@fnal.gov)

2> In your home directory at d0mino create a directory bbft-lyon.
   $mkdir bbftp-lyon (this is hyphen -, not underscore _).

3> Go to your production directory,
   mc_runjob
   and do
   ./createdb.sh  ( this will create full-database)
   ./create-import.sh (this will create full-import)

   to create required data base files.
   It is better to run only one generator job from one production directory.
   
4> Either go to your public area or create an area in $GROUP_DIR
   for file transfer.
   I have created an area 
   /afs/in2p3.fr/group/d0/prod-fake/transfer (name is not important)
   
   $cd /afs/in2p3.fr/group/d0/prod-fake/transfer
   $tar xvf ~evelyne/public/d0/d0_bbftp.tar

5> Edit the file 
   /afs/in2p3.fr/group/d0/prod-fake/transfer/d0_bbftp/run_ftp_bbftp.csh 
   to put the name of your production directory.
   The relevant line is

   set pwd_prod=$GROUP_DIR'/'$prod'/simulatepmc02.01ccreal/mc_runjob'

6> Then run the script run_ftp_bbftp.csh by doing
   $./run_ftp_bbftp.csh prod-fake jetefake /sam/cache2/import

   here prod-fake is the mother directory from where my production
   directory is hanging.

   Third field, that is jetefake is the process.

   Fourth field is the destination directory in d0mino
   here /sam/cache2/import, but you might use /sam/cache1/import
   depending on which one is free.

   Answer all questions on the affirmative.

7> If it is not already there with proper contents create a file
   .netrc in your home directory at Lyon and put the following lines

   machine d0mino.fnal.gov
   login 'your user name'
   password 'your pass on d0mino.fnal.gov'

   Not to mention, as this file contains your password please put the
   protection correctly so that no one but you has any access to this file.
   You may do
   chmod 700 .netrc

8> Login to d0mino and copy in your bbftp-lyon the file
   ~lebreton/test-bbftpc.v-1.8.8
   This file should be executable, if not for some reason change it by
   using chmod.

9> Do the following to check that your python script for import is fine.
   $setup n32
   $setup sam
   $setup python
   $cd /sam/cache2/import
   $python my-import-file
   If you don't get any message, it means everything is fine.

9> Do
   $bbftp -i in_prod-fake.time-stamp -u parua -p 5 -o out_prod-fake.time-stamp
    -b ccsrv13.in2p3.fr

   This will ask you for a password, give the password for ccali.

10> It will take a while to transfer all files.
 
11> You must change protection to all files that you transfered to sam,
    so that people can delete your files.
    do
    chmod 777 *.params  | import.py | gen.* | sim.* 


Cleaning up the disk after production:
--------------------------------------
1> Go to the mc_runjob directory

2> Run the script shortlog.sh to remove unnecessary details from the log file.
   ./shortlog.sh

3> $tar cvf myprod_jetefake.tar mc_run_job

4> $gzip  myprod_jetefake.tar 
  
5> $elliotc archive -G y -c "comment describing the production"  
     myprod_jetefake.tar.gz