Example #1
0
    def __init__(self, mw_param='', run_name='', auto=0):
        """ initialisation of the object """

        #init
        self.y = {}
        self.dy = {}
        self.event = {}  #to verify that all bin have the same number of data

        #charge parameter
        if run_name == '' and mw_param == '':
            self.MWparam = MW_param.MW_info('MadWeight_card.dat')
        elif mw_param == '':
            self.MWparam = MW_param.MW_info(run_name + '_banner.txt')
        else:
            self.MWparam = mw_param

        self.run_type = self.MWparam.info['mw_parameter'][
            '1']  #how are use/generated param_card
        self.name = self.MWparam.name

        #init step 2
        for k in self.MWparam.actif_param:
            self.y[k] = 0
            self.dy[k] = 0
            self.event[k] = 0

        #launch everything
        if auto:
            self.make_all()
Example #2
0
 def __init__(self,name='acceptance'):
     """read the card"""
     
     MW_param.go_to_main_dir()
     self.MWparam=MW_param.MW_info('MadWeight_card.dat')
     self.name=name
     self.dir=os.getcwd().split('/')[-1]
     os.system('mkdir Events/'+self.MWparam.name)
     os.system('mkdir Events/'+self.MWparam.name+'/Acceptance')
     create_param.Param_card(run_name=self.MWparam)
     self.MWparam.update_nb_card()        
     os.chdir('..')
    def __init__(self, directory, lhco_file='', MWparam=''):
        """ input is either a file containing particule number info or a SubProcesses directory """

        if MWparam:
            self.MWparam = MWparam
        else:
            import MW_param
            self.MWparam = MW_param.MW_info('MadWeight_card.dat')

        #treat directory info
        if directory.count('SubProcesses'):
            self.directory = directory
        else:
            self.directory = './SubProcesses/' + directory

        # find number of particle of each type
        if os.path.isfile(self.directory + 'info_part.dat'):
            self.extract_file_info(self.directory)
        else:
            self.load_particle_number(self.directory)

        self.init_hlt_cut()

        if self.MWparam.info.has_key('hltcut'):
            self.update_hlt_cut()

        if lhco_file:
            self.verif_event(lhco_file)
    def create_set_card(self,name):
        """ create all the card from schedular in file name """

        if type(name)==str:
            self.MWparam=MW_param.read_card(name)
        else:
            self.MWparam=name
            
        if self.MWparam['mw_parameter']['2']:
            self.file_ParamInfo=open('./Cards/info_card.dat','a')	
        else:
            self.file_ParamInfo=open('./Cards/info_card.dat','w')	
        self.define_mapping_file()
            
        param_list=self.create_change_tag(self.MWparam)
        if not self.source:
            self.charge_card('param_card.dat')            
        if self.MWparam['mw_parameter']['1']=='0':
            self.check_exist()
            self.define_mapping_file_for0gen()
            return
        elif self.MWparam['mw_parameter']['1']=='1':
            self.del_old_param()
            num=self.generated_uncorolated_card(param_list)
        elif self.MWparam['mw_parameter']['1']=='2':
            self.del_old_param()
            num=self.generated_corolated_card(param_list)

        print 'we have created ',num-1,' param_card\'s'

        if self.MWparam['mw_parameter']['2']:
            self.update_event_dir()
Example #5
0
    def __init__(self):
        self.lhco_file = raw_input(
            'enter the name of the file to test : ').split()[0]
        Card_pos = raw_input(
            'give position to a MadWeight_card.dat: ').split()[0]
        import MW_param
        self.MWparam = MW_param.MW_info(Card_pos)
        val = ''
        while val not in ['0', '1']:
            val = raw_input('use the file info_part.dat (0/1)?')
        if val == '1':
            self.partdef = self.extract_file_info()
        else:
            self.nb_part = {}
            for element in [
                    'jet', 'bjet', 'electron', 'positron', 'muon', 'amuon',
                    'tau', 'atau', 'miss'
            ]:
                value = raw_input(
                    'enter authorize value for the nb of particule of type ' +
                    element + ' : ')
                value.split()
                if len(value) == 1: self.nb_part[element] = int(value[0])
                else: self.nb_part[element] = value
            self.nb_part['photon'] = 0

        partdef = lhco_all_particles_def()
        if not self.MWparam.info['mw_perm']['21']:
            partdef.use_bjet()
        if self.MWparam.info.has_key('eventselection'):
            partdef.update_hlt_cut(self.MWparam.info['eventselection'])
        self.partdef = partdef
        #define internal variable
        self.write_events = 0
        self.verif_event(self.lhco_file, self.partdef, output=1)
Example #6
0
    def __init__(self,
                 directory,
                 lhco_file='',
                 MWparam='',
                 auto=1,
                 write_mode=1):
        """ input is either a file containing particule number info or a SubProcesses directory """

        start = time.time()
        if MWparam:
            self.MWparam = MWparam
        else:
            import MW_param
            self.MWparam = MW_param.MW_info('MadWeight_card.dat')
        self.write_mode = write_mode

        #treat directory info
        if directory.count('SubProcesses'):
            self.directory = directory
        else:
            self.directory = './SubProcesses/' + directory

        self.lhco_file = lhco_file
        self.partdef = self.find_particle_number(
        )  # find number of particle of each type

        #define internal variable
        self.write_events = 0
        print 'time  init Lhco_filter', time.time() - start
        if lhco_file and auto:
            self.verif_event(lhco_file, self.partdef)
Example #7
0
    def create_set_card(self, name):
        """ create all the card from schedular in file name """

        if type(name) == str:
            self.MWparam = MW_param.read_card(name)
        else:
            self.MWparam = name

        if self.MWparam['mw_parameter']['2']:
            self.file_ParamInfo = open('./Cards/info_card.dat', 'a')
        else:
            self.file_ParamInfo = open('./Cards/info_card.dat', 'w')
        self.define_mapping_file()

        param_list = self.create_change_tag(self.MWparam)
        if not self.source:
            self.charge_card('param_card.dat')
        if self.MWparam['mw_parameter']['1'] == '0':
            self.check_exist()
            self.define_mapping_file_for0gen()
            return
        elif self.MWparam['mw_parameter']['1'] == '1':
            self.del_old_param()
            num = self.generated_uncorolated_card(param_list)
        elif self.MWparam['mw_parameter']['1'] == '2':
            self.del_old_param()
            num = self.generated_corolated_card(param_list)

        print 'we have created ', num - 1, ' param_card\'s'

        if self.MWparam['mw_parameter']['2']:
            self.update_event_dir()
Example #8
0
 def oneSetUp(self):
     """prepare the runs """
     os.system('./bin/PassToMadWeight')
     os.system('rm ./Cards/proc_card_mg5.dat')
     os.system('ln -s ../Source/MadWeight/test_files/proc_card_mg5.dat ./Cards')
     os.system('./bin/newprocess')
     os.system('./bin/madweight.py -12')
     self.MWparam = MW_param.MW_info('MadWeight_card.dat')
Example #9
0
    def write_card(self,name):
        """write the param_card with name $name """

        if 1:

        #try:
            num=int(name[11:-4])
            self.create_info_line(num)
        #except:
        #    pass

        MW_param.go_to_main_dir()
        ff=open('./Cards/'+name,'w')
        if self.source:
            #charge the comment from the original card
            gg=open('./Cards/'+self.source,'r')
            while 1:
                line=gg.readline()
                if line=='':
                    break
                if line[0]=="#":
                    ff.writelines(line)
                else:
                    break
            gg.close()

        decay=0
        for key in self.info.keys():
            if key in ['decay','br']:
                decay=1
                continue
            if key=="comment":
                continue
            text=self.create_blok_text(key)
            ff.writelines(text)

        if decay:
            text=self.create_decay_text()
            ff.writelines(text)
            
        ff.close()
        self.creating_card+=1
Example #10
0
    def write_card(self, name):
        """write the param_card with name $name """

        if 1:

            #try:
            num = int(name[11:-4])
            self.create_info_line(num)
        #except:
        #    pass

        MW_param.go_to_main_dir()
        ff = open('./Cards/' + name, 'w')
        if self.source:
            #charge the comment from the original card
            gg = open('./Cards/' + self.source, 'r')
            while 1:
                line = gg.readline()
                if line == '':
                    break
                if line[0] == "#":
                    ff.writelines(line)
                else:
                    break
            gg.close()

        decay = 0
        for key in self.info.keys():
            if key in ['decay', 'br']:
                decay = 1
                continue
            if key == "comment":
                continue
            text = self.create_blok_text(key)
            ff.writelines(text)

        if decay:
            text = self.create_decay_text()
            ff.writelines(text)

        ff.close()
        self.creating_card += 1
Example #11
0
    def test_autofiles(self):
        if not self.checkSetUp():
            self.oneSetUp()
        else:
            self.MWparam = MW_param.MW_info('MadWeight_card.dat')

        for MWdir in self.MWparam.MW_listdir:
            for filename in ['main_code%s.f', 'data%s.inc','d_choices%s.f','d_choices%s.inc','info_part%s.dat','multi_channel%s.f','transfer_functions%s.f']:
                text = 'diff ./SubProcesses/%s/' + filename + ' ./Source/MadWeight/test_files/'+ filename
                os.system(text % (MWdir, '', MWdir[4]))
                self.assertTrue(filecmp.cmp(os.path.join('./SubProcesses/',MWdir, filename % ''), './Source/MadWeight/test_files/' + filename % MWdir[4], False),
                                'not valid file %s in process %s' % (filename % '', MWdir))
Example #12
0
    def create_set_card(self, name):
        """ create all the card from schedular in file name """
        self.creating_card = 1  #tag to know card under creation
        self.wrong_generation = [
        ]  #can happen if fct is wrongly defined -> automatic desactivation

        if type(name) == str:
            self.MWparam = MW_param.read_card(name)
        else:
            self.MWparam = name

        if self.MWparam['mw_parameter']['2']:
            self.file_ParamInfo = open('./Cards/info_card.dat', 'a')
        else:
            print 'define new mapping file'
            self.file_ParamInfo = open('./Cards/info_card.dat', 'w')

        param_list = self.create_change_tag(self.MWparam)

        if not self.source:
            self.charge_card('param_card.dat')
        if self.MWparam['mw_parameter']['1'] == 0:
            self.check_exist()
            self.define_mapping_file()
            return
        elif self.MWparam['mw_parameter']['1'] == 1:
            self.del_old_param()
            num = self.generated_uncorolated_card(param_list)
        elif self.MWparam['mw_parameter']['1'] == 2:
            self.del_old_param()
            num = self.generated_corolated_card(param_list)

        self.define_mapping_file()
        print 'we have created ', num - 1, ' param_card\'s'
        if self.wrong_generation:
            print 'but ', len(self.wrong_generation), ' are desactivated'

        if self.MWparam['mw_parameter']['2']:
            self.update_event_dir()
Example #13
0
    def create_set_card(self,name):
        """ create all the card from schedular in file name """
        self.creating_card=1 #tag to know card under creation
        self.wrong_generation=[] #can happen if fct is wrongly defined -> automatic desactivation
        
        if type(name)==str:
            self.MWparam=MW_param.read_card(name)
        else:
            self.MWparam=name
        
        if self.MWparam['mw_parameter']['2']:
            self.file_ParamInfo=open('./Cards/info_card.dat','a')	            
        else:
            print 'define new mapping file'
            self.file_ParamInfo=open('./Cards/info_card.dat','w')	            

        param_list=self.create_change_tag(self.MWparam)

        if not self.source:
            self.charge_card('param_card.dat')            
        if self.MWparam['mw_parameter']['1'] == 0:
            self.check_exist()
            self.define_mapping_file()
            return
        elif self.MWparam['mw_parameter']['1'] == 1:
            self.del_old_param()
            num=self.generated_uncorolated_card(param_list)
        elif self.MWparam['mw_parameter']['1'] == 2:
            self.del_old_param()
            num=self.generated_corolated_card(param_list)

        self.define_mapping_file()
        print 'we have created ',num-1,' param_card\'s'
        if self.wrong_generation:
            print 'but ',len(self.wrong_generation),' are desactivated'
                        
        if self.MWparam['mw_parameter']['2']:
            self.update_event_dir()
Example #14
0
                                
def check_valid(text):
    for name in forbiden:
        Pattern=re.compile(name,re.I)
        if Pattern.search(text):
            print "ERROR: invalid usage of statement: ",name
            print "for security reason transfer functions can't use this statement"
            sys.exit()
    return
        
###########################   TEST   #################################
if(__name__=="__main__"):

    import MW_param
    MW_param.go_to_main_dir()
    os.chdir('./Source/MadWeight_File/Transfer_Fct')

    opt=sys.argv
    if len(opt)<2:
        listdir=os.listdir('./data')
        print 'Available TF function:\n   ',
        print '\n    '.join([content[3:-4] for content in listdir if (content[0:2]=='TF' and content[-3:]=='dat')])
        name=raw_input('Choose your Transfer Function\n')
    else:
        name=opt[1]
    if len(opt)==3:
        made_make=int(opt[2])
    else:
        made_make=0
    create_TF_main(name,made_make)
#    dir_sche=create_dir(MW_param)
#    dir_sche.all()
#    os.chdir("../../../")
#    print 'created',dir_sche.created,'directories'
#    return dir_sche.created


def create_all_schedular(MWparam):

    for directory in MWparam.MW_listdir + MWparam.P_listdir:
        try:
            os.mkdir('./SubProcesses/' + directory + '/schedular')
        except:
            pass


##############################################################################################
##                                  Single Launch                                           ##
##############################################################################################
if __name__ == '__main__':

    #reupdate all the active card to a certain nuber of event
    #import global run opt
    import MW_param
    MW_param.go_to_main_dir()
    MWparam = MW_param.MW_info('MadWeight_card.dat')

    #launch the check
    create_obj = create_dir(MWparam)
    create_obj.update_card_status()
 def charge_card(self,name):
     """ charge the card """
     self.source=name
     self.info=MW_param.read_card(name)
Example #17
0
        #adding card information
        self.card_info['MWCard'] = './Cards/MadWeight_card.dat'
        self.card_info['TransferCard'] = './Cards/transfer_card.dat'

    #2 #######################################################################
    def write(self):
        """   |   main schedular to write the banner                           ##
        """

        self.put_header()  #put default header
        self.put_version_info()  #define the version of all the part
        self.put_info_card()  #define all the text linked to the card
        self.write_file()  #write the file


############################################################################
if '__main__' == __name__:
    """ if this script is launched by hand do the old put banner of MG_ME """

    def_pos = MW_param.move()
    def_pos.to_main()
    opt = sys.argv
    if len(opt) == 1:
        filename = input('Enter file with events (in directory Events)')
    else:
        filename = opt[1]

    me_banner = ME_Banner(filename, initdir=def_pos.initpos)
    me_banner.write()
Example #18
0
        self.version_info['Transfer_Function version']='./Source/MadWeight/transfer_function/Transfer_FctVersion.txt'

        #adding card information
        self.card_info['MWCard']='./Cards/MadWeight_card.dat'
        self.card_info['TransferCard']='./Cards/transfer_card.dat'

    #2 #######################################################################        
    def write(self):
        """   |   main schedular to write the banner                           ##
        """
        
        self.put_header()          #put default header
        self.put_version_info()    #define the version of all the part
        self.put_info_card()       #define all the text linked to the card
        self.write_file()          #write the file

############################################################################
if '__main__'==__name__:
    """ if this script is launched by hand do the old put banner of MG_ME """

    def_pos=MW_param.move()
    def_pos.to_main()
    opt=sys.argv
    if len(opt)==1:
        filename=raw_input('Enter file with events (in directory Events)')
    else:
        filename=opt[1]
    
    me_banner=ME_Banner(filename,initdir=def_pos.initpos)
    me_banner.write()
Example #19
0
    """ read the file to find the requested change of variable"""
    
    found=0
    for line in file(filepos):
        if found:
            name=line.split()[0] #remove blank spae,end of line,...
            return name
        if line.startswith('# Begin transfer_function'):
            found=1

        
###########################   TEST   #################################
if(__name__=="__main__"):

    import MW_param
    MW_param.go_to_main_dir()

    P_dir,MW_dir=MW_param.detect_SubProcess(P_mode=1)

    opt=sys.argv
    if len(opt)<2:
        listdir=os.listdir('./Source/MadWeight/transfer_function/data')
        print 'Available TF function:\n   ',
        print '\n    '.join([content[3:-4] for content in listdir if (content.startswith('TF') and content.endswith('dat'))])
        name=raw_input('Choose your Transfer Function\n')
    else:
        name=opt[1]
        if name in ['proc_card.dat','auto']:
            name=extract_tf_name('./Cards/proc_card.dat')
    if len(opt)==3:
        made_make=int(opt[2])
Example #20
0
    def FindCardName(self,tag):
        if tag in list(dico.keys()):
            if '.' not in dico[tag]:
                return dico[tag]+'.dat'
            else:
                return dico[tag]
        else:
            import time
            out=tag.split('_',1)
            name=self.FindCardName(out[0])
            return name.split('.',1)[0]+'_'+out[1]+'.dat'

if __name__=='__main__':
    import MW_param
    MW_param.go_to_main_dir()
    opt=sys.argv
    print(opt)
    if len(opt)<2:
       name=input('enter the run name to restore or the position of a banner file\n')
    else:
        name=opt[1]

    if ('/' not in name):
        ban=banner('./Events/'+name+'/'+name+'_banner.txt')
        pos='./Events/'+name+'/'
    else:
        ban=banner(name)
        pos='/'.join([part for part in name.split('/')[:-1]])
        
    ban.split()
Example #21
0
 def charge_card(self, name):
     """ charge the card """
     self.source = name
     self.info = MW_param.read_card(name)