MadWeightAdvancedOpttion: generate_min_events.py.txt

File generate_min_events.py.txt, 4.4 KB (added by trac, 7 years ago)
Line 
1#!/usr/bin/env python
2#********************************************************************************
3#
4#       Code by Olivier Mattelaer (olivier.mattelaer@uclouvain.be)
5#       last modification 26/02/2010
6#       License GNU
7#********************************************************************************
8#
9#  In order to use this script you shoud define a valid MadWeight Card
10#
11#  On this one the relevant blok are:
12#  Block MW_parameter (defining the set of MW_card)
13#  Block EventSelection (defining event selection: detail at http://cp3wks05.fynu.ucl.ac.be/twiki/bin/view/Software/MadWeightAdvancedOpttion#Block_EventSelection)
14#
15#  All the other standard input of the MW card are irrelevant.
16#  In the blok MW_run you need to add the line
17#  requested XXXX
18#  this will indicated the number of LHCO events you need after cuts.
19#
20#******************************************************************************
21
22
23
24
25
26
27#Extension
28import string
29import sys
30import os
31import re
32import time
33import stat
34# patch if symbolic directory replace by real file
35sys.path.append('./Source/MadWeight_File/Python')
36sys.path.append('../Source/MadWeight_File/Python')
37#end patch
38import write_MadWeight,create_run,put_banner
39import create_param
40import Cards
41from Cards import Card
42import cluster_lib as Cluster
43from create_run import update_cuts_status
44from MW_param import MW_info,go_to_main_dir,check_for_help
45from collect_result import Collect_dir,Collect_P_dir,Collect_MW_dir,Collect_All_dir,collect_schedular
46import verif_event
47
48
49class Lhco_filter(verif_event.Lhco_filter):
50   
51    #2 ###############################################################################################################
52    def __init__(self, input_file,MWparam,auto=1):
53        """ input is either a file containing particule number info or a SubProcesses directory """
54
55        start=time.time()
56
57        self.MWparam=MWparam
58        #treat directory info
59        self.directory='./SubProcesses/'+MWparam.P_listdir[0]
60               
61        self.lhco_file=input_file
62        self.partdef=self.find_particle_number()        # find number of particle of each type
63           
64        #define internal variable
65        self.write_mode = 1
66        self.write_events=0
67        print 'time  init Lhco_filter',time.time()-start
68        #if input_file and auto:
69        #    self.verif_event(input_file,self.partdef)
70
71    def launch_verif(self,input_file=''):
72        if input_file=='':
73            input_file = self.lhco_file
74        nb_event=self.verif_event(input_file,self.partdef)
75        return nb_event
76   
77    def add_in_file(self,output_file):
78       
79        try:
80                self.f_out.close()
81        except:
82                pass
83        ff=open(output_file,'a')
84        ff.writelines(open(self.directory+'/'+self.MWparam.name+'/verif.lhco','r').read())
85        ff.close()
86             
87                   
88
89def check_event(input_file,output_file,MWparam):
90
91    select = Lhco_filter(input_file,MWparam)
92    nb_select = select.launch_verif(input_file)
93    print 'nb_select',nb_select,type(nb_select)
94    select.add_in_file(output_file)
95
96    return nb_select
97                                                               
98#####################################################################################"
99##
100##               LAUNCH PROGRAM
101##
102######################################################################################
103if(__name__=='__main__'):
104
105    go_to_main_dir()
106    check_for_help(sys.argv)
107    MWparam=MW_info('MadWeight_card.dat')
108    MWparam.set_run_opt(sys.argv)
109    create_param.Param_card(run_name=MWparam)
110    MWparam.update_nb_card()
111
112    os.system('rm Events/card_*')
113    os.system('rm Events/valid_*')
114    for i in range(1,MWparam.nb_card+1):
115        pass_event=0
116        os.system('cp Cards/param_card_%s.dat Cards/param_card.dat' % i)
117        for j in range(0,100):
118            os.system('./bin/generate_events 1 card_%s_run_%s  card_%s_run_%s' %(i,j,i,j))
119            os.system('gunzip Events/card_%s_run_%s_pgs_events.lhco.gz' %(i,j))
120            pass_event+=check_event('Events/card_%s_run_%s_pgs_events.lhco' %(i,j),'Events/valid_events_card_%s.lhco' % (i),MWparam)
121            os.system('rm Events/card_%s_run_%s_*' %(i,j))
122            print pass_event,MWparam['mw_run']['requested']
123            if pass_event>int(MWparam['mw_run']['requested']):
124                break
125           
126           
127#            signal_2Hdm_1_pgs_uncleaned_events.lhco.gz
128
129       
130#    verif_event(MWparam)