~maddm/maddm/python3

« back to all changes in this revision

Viewing changes to maddm_run_interface.py

  • Committer: olivier-mattelaer
  • Date: 2019-01-10 10:53:52 UTC
  • Revision ID: olivier-mattelaer-20190110105352-1gz33e14d8v3ahh7
pass to 3.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
572
572
cm22pb  = 1.00E36
573
573
pb2cm3 = 2.99E-26
574
574
 
 
575
def secure_float_f77(d):
 
576
    try:
 
577
        return float(d)
 
578
    except ValueError:
 
579
        m=re.search(r'''([+-]?[\d.]*)([+-]\d*)''', d)
 
580
        if m:
 
581
            return float(m.group(1))*10**(float(m.group(2)))
 
582
        raise
575
583
 
576
584
 
577
585
#===============================================================================
813
821
                else:
814
822
                    if self._two2twoLO:
815
823
                        if 'sigma*v' in line: 
816
 
                            sigv_temp = float(splitline[1])
 
824
                            sigv_temp = secure_float_f77(splitline[1])
817
825
                            oname = splitline[0].split(':',1)[1] .split('_')
818
826
                            oname = oname[0]+'_'+oname[1] #To eliminate the annoying suffix coming from the '/' notation
819
827
                            result['taacsID#'     + oname] = sigv_temp 
825
833
                            elif oname.split('_')[1] not in self.limits._allowed_final_states:
826
834
                                result['lim_taacsID#'+oname] = -1
827
835
                            sigv_indirect += sigv_temp
828
 
                    result[splitline[0].split(':')[0]] = float(splitline[1])
 
836
                    result[splitline[0].split(':')[0]] = secure_float_f77(splitline[1])
829
837
 
830
838
                    
831
839
        result['taacsID'] = sigv_indirect
1030
1038
        
1031
1039
        if not self.in_scan_mode: 
1032
1040
            logger.info('Running indirect detection')
1033
 
            
1034
 
        if not hasattr(self, 'me_cmd'):
1035
 
            self.me_cmd = Indirect_Cmd(pjoin(self.dir_path, 'Indirect'), force_run=True)
1036
 
            #force_run = True means no crash associated with RunWeb -> we check this later
1037
 
        elif self.me_cmd.me_dir != pjoin(self.dir_path, 'Indirect'):
1038
 
            self.me_cmd.do_quit()
1039
 
            self.me_cmd = Indirect_Cmd(pjoin(self.dir_path, 'Indirect'), force_run=True)
1040
 
            #force_run = True means no crash associated with RunWeb -> we check this later
1041
 
            
 
1041
        
 
1042
        if not  self._two2twoLO:   
 
1043
            if not hasattr(self, 'me_cmd'):
 
1044
                self.me_cmd = Indirect_Cmd(pjoin(self.dir_path, 'Indirect'), force_run=True)
 
1045
                #force_run = True means no crash associated with RunWeb -> we check this later
 
1046
            elif self.me_cmd.me_dir != pjoin(self.dir_path, 'Indirect'):
 
1047
                self.me_cmd.do_quit()
 
1048
                self.me_cmd = Indirect_Cmd(pjoin(self.dir_path, 'Indirect'), force_run=True)
 
1049
                #force_run = True means no crash associated with RunWeb -> we check this later
 
1050
                
1042
1051
        mdm = self.param_card.get_value('mass', self.proc_characteristics['dm_candidate'][0])
1043
1052
 
1044
1053
        if self.maddm_card['sigmav_method'] != 'inclusive':
2986
2995
        #For setting the exp. constraints
2987
2996
        elif args[0] == 'dd_si_limits':
2988
2997
            if len(args) >2:
2989
 
                self.limits._sigma_SI = float(args[1])
2990
 
                self.limits._sigma_SI_width = float(args[2])
 
2998
                self.limits._sigma_SI = secure_float_f77(args[1])
 
2999
                self.limits._sigma_SI_width = secure_float_f77(args[2])
2991
3000
            else:
2992
3001
                logger.info('The file you use for direct detection limits will be interpreted as:')
2993
3002
                logger.info('Column 1 - dark matter mass in GeV')
3026
3035
 
3027
3036
        elif args[0] == 'relic_limits':
3028
3037
            logger.info('The info is interpreted as: <Oh^2>, CL width')
3029
 
            self.limits._oh2_planck = float(args[1])
3030
 
            self.limits._oh2_planck_width = float(args[2])
 
3038
            self.limits._oh2_planck = secure_float_f77(args[1])
 
3039
            self.limits._oh2_planck_width = secure_float_f77(args[2])
3031
3040
 
3032
3041
        elif args[0] == 'id_limits':
3033
3042
             if len(args)!= 4:
3040
3049
 
3041
3050
             if len(args) > 4:
3042
3051
                 if args[2] in self.limits._allowed_final_states:
3043
 
                    self.limits._id_limit_vel[args[2]] = float(args[1])
3044
 
                    self.limits._sigma_ID[args[2]] = float(args[3])
3045
 
                    self.limits._sigma_ID_width[args[2]] = float(args[4])
 
3052
                    self.limits._id_limit_vel[args[2]] = secure_float_f77(args[1])
 
3053
                    self.limits._sigma_ID[args[2]] = secure_float_f77(args[3])
 
3054
                    self.limits._sigma_ID_width[args[2]] = secure_float_f77(args[4])
3046
3055
                 else:
3047
3056
                     logger.error('Final state not allowed for ID limits!')
3048
3057
             else:
3049
 
                 vel = float(args[1])
 
3058
                 vel = secure_float_f77(args[1])
3050
3059
                 channel = args[2]
3051
3060
                 id_file = args[3]
3052
3061
                 self.limits._id_limit_vel[channel] = vel
3109
3118
                    continue
3110
3119
                spline = line.split()
3111
3120
                jfact = spline[0]
3112
 
                dist = float(spline[1])
3113
 
                val = float(spline[2].rstrip())
 
3121
                dist = secure_float_f77(spline[1])
 
3122
                val = secure_float_f77(spline[2].rstrip())
3114
3123
                temp[jfact] = val
3115
3124
                temp2[jfact]= dist
3116
3125
            self['jfactors'] = temp
3546
3555
                    half_gauss = spline[2]
3547
3556
                    self.options['loglikelihood'][type] = half_gauss
3548
3557
                    if len(spline)==4:
3549
 
                        width_val = float(spline[3])
 
3558
                        width_val = secure_float_f77(spline[3])
3550
3559
                        self.options['half_gauss_width'][type] = width_val
3551
3560
                else:
3552
3561
                    spline = line.split('#')[0].split()
3558
3567
                        var_name = spline[1]
3559
3568
                        min = spline[2]
3560
3569
                        max = spline[3]
3561
 
                        self.options['parameters'].append([var_name, float(min), float(max)])
 
3570
                        self.options['parameters'].append([var_name, secure_float_f77(min), secure_float_f77(max)])
3562
3571
                    elif opt1 =='output_variables':
3563
3572
                        for j in range(1, len(spline)):
3564
3573
                            if spline[j] not in self.output_observables: