def load_particles_file(self,filepos='./Source/MODEL/particles.dat'): """ load the particles file if not already loaded """ if not self.particles_file: self.particles_file = Cards.Particles_file(filepos)
def define_tf_width(self, file): """ assign width of the TF function for all external particle """ if not hasattr(self, 'ParticlesFile'): self.ParticlesFile = Cards.Particles_file( './Source/MODEL/particles.dat') dico_pid_to_label = self.ParticlesFile.give_pid_to_label() dico_type_to_tflevel = {} has_theta_tf, has_phi_tf = [], [] ff = open(file, 'r') #pattern pattern = re.compile(r'''^\s*(?P<width>\w+)\s+(?P<type>[\w,01]*)''', re.VERBOSE) #read file while 1: line = ff.readline() if line == '': break if pattern.search(line): re_obj = pattern.search(line) if re_obj.group('width').lower() == 'delta': tf_level = 0 elif (re_obj.group('width').lower() == 'thin'): tf_level = 1 elif (re_obj.group('width').lower() == 'x'): self.x_constrained = int(re_obj.group('type')) continue elif (re_obj.group('width').lower() == 'theta'): list = re_obj.group('type').split(',') for tag in list: has_theta_tf.append(tag) continue elif (re_obj.group('width').lower() == 'phi'): list = re_obj.group('type').split(',') for tag in list: has_phi_tf.append(tag) continue else: tf_level = 2 list = re_obj.group('type').split(',') for tag in list: dico_type_to_tflevel[tag] = tf_level #put information in external particle for part in self.ext_content: try: label = dico_pid_to_label[abs(part.pid)] except KeyError: logger.info( 'particle with pdg %s has no transfer function define: Treated as missing energy' % part.pid) label = None if not part.neutrino: if label in dico_type_to_tflevel: part.tf_level = dico_type_to_tflevel[label] else: part.tf_level = 0 #delta is the default else: part.tf_level = 3 if label in has_theta_tf: part.has_theta_tf = True if label in has_phi_tf: part.has_phi_tf = True