Beispiel #1
0
    def configure(self):
        os.chdir(pjoin(self.me_dir))
        self.__CMD__initpos = self.me_dir

        time_mod = max([
            os.path.getctime(pjoin(self.me_dir, 'Cards', 'run_card.dat')),
            os.path.getctime(pjoin(self.me_dir, 'Cards', 'MadWeight_card.dat'))
        ])


        if self.configured > time_mod and \
                           hasattr(self,'MWparam') and hasattr(self,'run_card'):
            return
        self.configured = time.time()

        self.MWparam = MW_info.MW_info(
            pjoin(self.me_dir, 'Cards', 'MadWeight_card.dat'))
        run_card = pjoin(self.me_dir, 'Cards', 'run_card.dat')
        self.run_card = banner.RunCard(run_card)

        if self.options['run_mode'] == 0:
            self.exec_cmd('set run_mode 2 --no_save')
            self.exec_cmd('set nb_core 1 --no_save')
        if not self.options['cluster_temp_path']:
            if self.options['run_mode'] == 2:
                logger.info(
                    'Options cluster_temp_path is required for MW run. Trying to run with /tmp',
                    '$MG:color:BLACK')
                self.exec_cmd('set cluster_temp_path /tmp --no_save')
            elif self.options['cluster_type'] != 'condor':
                raise Exception, 'cluster_temp_path needs to be define for MW. Please retry.'
Beispiel #2
0
    def do_define_transfer_fct(self, line):
        """MadWeight Function:Define the current transfer function"""

        with misc.chdir(self.me_dir):
            self.configure()
            args = self.split_arg(line)

            path = pjoin(self.me_dir, 'Source', 'MadWeight',
                         'transfer_function', 'data')
            listdir = os.listdir(path)
            question = 'Please choose your transfer_function between\n'
            possibilities = [content[3:-4] for content in listdir \
                         if (content.startswith('TF') and content.endswith('dat'))]
            for i, tfname in enumerate(possibilities):
                question += ' %s / %s\n' % (i, tfname)
            possibilities += range(len(possibilities))

            if args and args[0] in possibilities:
                tfname = args[0]
            else:
                tfname = self.ask(question, 'dbl_gauss_pt_jet', possibilities)
            if tfname.isdigit():
                tfname = possibilities[int(tfname)]

            P_dir, MW_dir = MW_info.detect_SubProcess(P_mode=1)
            os.chdir('./Source/MadWeight/transfer_function')
            change_tf.create_TF_main(tfname, 0, MW_dir)
Beispiel #3
0
 def do_define_transfer_fct(self, line):
     """MadWeight Function:Define the current transfer function"""
     
     with misc.chdir(self.me_dir):  
         self.configure()
         args = self.split_arg(line)
         
         path = pjoin(self.me_dir, 'Source', 'MadWeight', 'transfer_function', 'data')
         listdir=os.listdir(path)
         question = 'Please choose your transfer_function between\n'
         possibilities = [content[3:-4] for content in listdir \
                      if (content.startswith('TF') and content.endswith('dat'))]
         for i, tfname in enumerate(possibilities):
             question += ' %s / %s\n' % (i, tfname)
         possibilities += range(len(possibilities))
         
         if args and args[0] in possibilities:
             tfname = args[0]
         else:
             tfname = self.ask(question, 'dbl_gauss_pt_jet', possibilities)
         if tfname.isdigit():
             tfname = possibilities[int(tfname)]
         
         P_dir, MW_dir = MW_info.detect_SubProcess(P_mode=1)
         os.chdir('./Source/MadWeight/transfer_function')
         change_tf.create_TF_main(tfname,0, MW_dir)
Beispiel #4
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']['bjet_is_jet_for_selection']:
            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)
Beispiel #5
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
        if lhco_file and auto:
            self.verif_event(lhco_file, self.partdef)
    def define_parameter(self,param_card):
        """define mass+width of all particle"""

        #load the information from the param card
        info=MW_param.read_card(param_card)

        for obj in self.content.values():
            obj.def_mass(info) #this routines defines also width if the particle is a propagator
Beispiel #7
0
    def define_parameter(self, param_card):
        """define mass+width of all particle"""

        #load the information from the param card
        info = MW_param.read_card(param_card)

        for obj in self.content.values():
            obj.def_mass(
                info
            )  #this routines defines also width if the particle is a propagator
Beispiel #8
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
Beispiel #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
Beispiel #10
0
    def __init__(self, info='default'):
        "initialize option"
        if isinstance(info, six.string_types) and info != 'default':
            info = MW_param.read_card(info)
        # DEFAULT VALUE:
        self.ecs_fuse = 1
        self.blob_fuse = 1
        self.use_sol_type_1 = 1
        self.use_sol_type_2 = 1
        self.use_sol_type_3 = 1
        self.max_sol = 10
        self.use_ecs_a = 1
        self.use_ecs_b = 1
        self.use_ecs_c = 1
        self.use_ecs_d = 1
        self.use_ecs_e = 1
        self.use_ecs_f = 1
        self.foce_nwa = 1e-9

        if info == 'default':
            return

        tag_to_genvar = {
            '1': 'self.ecs_fuse',
            '2': 'self.blob_fuse',
            '3': 'self.max_sol',
            '4': 'self.use_sol_type_1',
            '5': 'self.use_sol_type_2',
            '6': 'self.use_sol_type_3',
            '10': 'self.use_ecs_a',
            '11': 'self.use_ecs_b',
            '12': 'self.use_ecs_c',
            '13': 'self.use_ecs_d',
            '14': 'self.use_ecs_e',
            '15': 'self.use_ecs_f',
            'force_nwa': 'self.force_nwa'
        }

        #replace defined value:
        for key, value in info['mw_gen'].items():
            if key in tag_to_genvar:
                exec('%s = %s' % (tag_to_genvar[key], value))

        self.ecs_on = []
        for letter in 'abcdef':
            cond = 'self.use_ecs_' + letter
            if eval(cond):
                self.ecs_on.append(letter)

        #
        self.force_nwa = max(self.force_nwa, float(info['mw_run']['nwa']))
    def __init__(self,info='default'):
       "initialize option"
       if isinstance(info, basestring) and info!='default':
            info=MW_param.read_card(info)
       # DEFAULT VALUE:
       self.ecs_fuse=1
       self.blob_fuse=1
       self.use_sol_type_1=1
       self.use_sol_type_2=1
       self.use_sol_type_3=1
       self.max_sol=10
       self.use_ecs_a=1
       self.use_ecs_b=1
       self.use_ecs_c=1
       self.use_ecs_d=1
       self.use_ecs_e=1
       self.use_ecs_f=1
       self.foce_nwa = 1e-9

       if info=='default':
           return
       
       tag_to_genvar={'1':'self.ecs_fuse',
                      '2':'self.blob_fuse',
                      '3':'self.max_sol',
                      '4':'self.use_sol_type_1',
                      '5':'self.use_sol_type_2',
                      '6':'self.use_sol_type_3',
                      '10':'self.use_ecs_a',
                      '11':'self.use_ecs_b',
                      '12':'self.use_ecs_c',
                      '13':'self.use_ecs_d',
                      '14':'self.use_ecs_e',
                      '15':'self.use_ecs_f',
                      'force_nwa':'self.force_nwa'}

       #replace defined value:
       for key, value in info['mw_gen'].items():
           if key in tag_to_genvar:
               exec('%s = %s' % (tag_to_genvar[key],value))

       self.ecs_on=[]
       for letter in 'abcdef':
           cond='self.use_ecs_'+letter
           if eval(cond):
               self.ecs_on.append(letter)
               
       #
       self.force_nwa = max(self.force_nwa, float(info['mw_run']['nwa']))
Beispiel #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()
Beispiel #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()
Beispiel #14
0
 def charge_card(self, name):
     """ charge the card """
     self.source = name
     self.info = MW_param.read_card(name)
Beispiel #15
0
 def charge_card(self,name):
     """ charge the card """
     self.source=name
     self.info=MW_param.read_card(name)