1 from __future__ import division
2
3 from __future__ import absolute_import
4 from __future__ import print_function
5 import itertools
6 import xml.etree.ElementTree as ET
7 import math
8
9 import os
10 import re
11 import shutil
12 import logging
13 import random
14 import six
15 StringIO = six
16 from six.moves import range
17
18 logger = logging.getLogger('madgraph.models')
19
20 try:
21 import madgraph.iolibs.file_writers as file_writers
22 import madgraph.various.misc as misc
23 except:
24 import internal.file_writers as file_writers
25 import internal.misc as misc
26
27 pjoin = os.path.join
30 """ a class for invalid param_card """
31 pass
32
34 """A class for a param_card parameter"""
35
36 - def __init__(self, param=None, block=None, lhacode=None, value=None, comment=None):
37 """Init the parameter"""
38
39 self.format = 'float'
40 if param:
41 block = param.lhablock
42 lhacode = param.lhacode
43 value = param.value
44 comment = param.comment
45 format = param.format
46
47 self.lhablock = block
48 if lhacode:
49 self.lhacode = lhacode
50 else:
51 self.lhacode = []
52 self.value = value
53 self.comment = comment
54
56 """ set the block name """
57
58 self.lhablock = block
59
61 """ initialize the information from a str"""
62
63 if '#' in text:
64 data, self.comment = text.split('#',1)
65 else:
66 data, self.comment = text, ""
67
68
69 data = data.split()
70 if any(d.startswith('scan') for d in data):
71 position = [i for i,d in enumerate(data) if d.startswith('scan')][0]
72 data = data[:position] + [' '.join(data[position:])]
73 if not len(data):
74 return
75 try:
76 self.lhacode = tuple([int(d) for d in data[:-1]])
77 except Exception:
78 self.lhacode = tuple([int(d) for d in data[:-1] if d.isdigit()])
79 self.value= ' '.join(data[len(self.lhacode):])
80 else:
81 self.value = data[-1]
82
83
84 try:
85 self.value = float(self.value)
86 except:
87 self.format = 'str'
88 pass
89 else:
90 if self.lhablock == 'modsel':
91 self.format = 'int'
92 self.value = int(self.value)
93
95 """ initialize the decay information from a str"""
96
97 if '#' in text:
98 data, self.comment = text.split('#',1)
99 else:
100 data, self.comment = text, ""
101
102 if ']]>' in data:
103 data = data.split(']]>',1)[0]
104
105
106 data = data.split()
107 if not len(data):
108 return
109 self.lhacode = [int(d) for d in data[2:]]
110 self.lhacode.sort()
111 self.lhacode = tuple([len(self.lhacode)] + self.lhacode)
112
113 self.value = float(data[0])
114 self.format = 'decay_table'
115
117 """ return a SLAH string """
118
119
120 format = self.format
121 if self.format == 'float':
122 try:
123 value = float(self.value)
124 except:
125 format = 'str'
126 self.comment = self.comment.strip()
127 if not precision:
128 precision = 6
129
130 if format == 'float':
131 if self.lhablock == 'decay' and not isinstance(self.value,six.string_types):
132 return 'DECAY %s %.{0}e # %s'.format(precision) % (' '.join([str(d) for d in self.lhacode]), self.value, self.comment)
133 elif self.lhablock == 'decay':
134 return 'DECAY %s Auto # %s' % (' '.join([str(d) for d in self.lhacode]), self.comment)
135 elif self.lhablock and self.lhablock.startswith('qnumbers'):
136 return ' %s %i # %s' % (' '.join([str(d) for d in self.lhacode]), int(self.value), self.comment)
137 else:
138 return ' %s %.{0}e # %s'.format(precision) % (' '.join([str(d) for d in self.lhacode]), self.value, self.comment)
139 elif format == 'int':
140 return ' %s %i # %s' % (' '.join([str(d) for d in self.lhacode]), int(self.value), self.comment)
141 elif format == 'str':
142 if self.lhablock == 'decay':
143 return 'DECAY %s %s # %s' % (' '.join([str(d) for d in self.lhacode]),self.value, self.comment)
144 return ' %s %s # %s' % (' '.join([str(d) for d in self.lhacode]), self.value, self.comment)
145 elif self.format == 'decay_table':
146 return ' %e %s # %s' % ( self.value,' '.join([str(d) for d in self.lhacode]), self.comment)
147 elif self.format == 'int':
148 return ' %s %i # %s' % (' '.join([str(d) for d in self.lhacode]), int(self.value), self.comment)
149 else:
150 if self.lhablock == 'decay':
151 return 'DECAY %s %d # %s' % (' '.join([str(d) for d in self.lhacode]), self.value, self.comment)
152 else:
153 return ' %s %d # %s' % (' '.join([str(d) for d in self.lhacode]), self.value, self.comment)
154
157 """ list of parameter """
158
160 if name:
161 self.name = name.lower()
162 else:
163 self.name = name
164 self.scale = None
165 self.comment = ''
166 self.decay_table = {}
167 self.param_dict={}
168 list.__init__(self)
169
170 - def get(self, lhacode, default=None):
171 """return the parameter associate to the lhacode"""
172 if not self.param_dict:
173 self.create_param_dict()
174
175 if isinstance(lhacode, int):
176 lhacode = (lhacode,)
177
178 try:
179 return self.param_dict[tuple(lhacode)]
180 except KeyError:
181 if default is None:
182 raise KeyError('id %s is not in %s' % (tuple(lhacode), self.name))
183 else:
184 return Parameter(block=self, lhacode=lhacode, value=default,
185 comment='not define')
186
188
189
190 for old_key, new_key in change_keys.items():
191
192 assert old_key in self.param_dict
193 param = self.param_dict[old_key]
194 del self.param_dict[old_key]
195 self.param_dict[new_key] = param
196 param.lhacode = new_key
197
198
200 """ remove a parameter """
201 list.remove(self, self.get(lhacode))
202
203 return self.param_dict.pop(tuple(lhacode))
204
205 - def __eq__(self, other, prec=1e-4):
206 """ """
207
208 if isinstance(other, str) and ' ' not in other:
209 return self.name.lower() == other.lower()
210
211
212 if len(self) != len(other):
213 return False
214
215 return not any(abs(param.value-other.param_dict[key].value)> prec * abs(param.value)
216 for key, param in self.param_dict.items())
217
218 - def __ne__(self, other, prec=1e-4):
219 return not self.__eq__(other, prec)
220
222
223 assert isinstance(obj, Parameter)
224 if not hasattr(self, 'name'):
225 self.__init__(obj.lhablock)
226 assert not obj.lhablock or obj.lhablock == self.name
227
228
229
230 if not hasattr(self, 'param_dict'):
231 self.param_dict = {}
232
233 if tuple(obj.lhacode) in self.param_dict:
234 if self.param_dict[tuple(obj.lhacode)].value != obj.value:
235 raise InvalidParamCard('%s %s is already define to %s impossible to assign %s' % \
236 (self.name, obj.lhacode, self.param_dict[tuple(obj.lhacode)].value, obj.value))
237 return
238 list.append(self, obj)
239
240 self.param_dict[tuple(obj.lhacode)] = obj
241
243 """create a link between the lhacode and the Parameter"""
244 for param in self:
245 self.param_dict[tuple(param.lhacode)] = param
246
247 return self.param_dict
248
250 """ """
251 self.scale = scale
252
254 "set inforamtion from the line"
255
256 if '#' in text:
257 data, self.comment = text.split('#',1)
258 else:
259 data, self.comment = text, ""
260
261 data = data.lower()
262 data = data.split()
263 self.name = data[1]
264 if len(data) == 3:
265 if data[2].startswith('q='):
266
267 self.scale = float(data[2][2:])
268 elif self.name == 'qnumbers':
269 self.name += ' %s' % data[2]
270 elif len(data) == 4 and data[2] == 'q=':
271
272 self.scale = float(data[3])
273
274 return self
275
277 """returns the list of id define in this blocks"""
278
279 return [p.lhacode for p in self]
280
282 """ return a str in the SLAH format """
283
284 text = """###################################""" + \
285 """\n## INFORMATION FOR %s""" % self.name.upper() +\
286 """\n###################################\n"""
287
288 if self.name == 'decay':
289 for param in self:
290 pid = param.lhacode[0]
291 param.set_block('decay')
292 text += str(param)+ '\n'
293 if pid in self.decay_table:
294 text += str(self.decay_table[pid])+'\n'
295 return text
296 elif self.name.startswith('decay'):
297 text = ''
298
299 elif not self.scale:
300 text += 'BLOCK %s # %s\n' % (self.name.upper(), self.comment)
301 else:
302 text += 'BLOCK %s Q= %e # %s\n' % (self.name.upper(), self.scale, self.comment)
303
304 text += '\n'.join([param.__str__(precision) for param in self])
305 return text + '\n'
306
309 """ a param Card: list of Block """
310 mp_prefix = 'MP__'
311
312 header = \
313 """######################################################################\n""" + \
314 """## PARAM_CARD AUTOMATICALY GENERATED BY MG5 ####\n""" + \
315 """######################################################################\n"""
316
317
319 dict.__init__(self,{})
320 self.order = []
321 self.not_parsed_entry = []
322
323 if isinstance(input_path, ParamCard):
324 self.read(input_path.write())
325 self.input_path = input_path.input_path
326 else:
327 self.input_path = input_path
328 if input_path:
329 self.read(input_path)
330
331 - def read(self, input_path):
332 """ read a card and full this object with the content of the card """
333
334 if isinstance(input_path, str):
335 if '\n' in input_path:
336 input = StringIO.StringIO(input_path)
337 else:
338 input = open(input_path)
339 else:
340 input = input_path
341
342
343 cur_block = None
344 for line in input:
345 line = line.strip()
346 if not line or line[0] == '#':
347 continue
348 line = line.lower()
349 if line.startswith('block'):
350 cur_block = Block()
351 cur_block.load_str(line)
352 self.append(cur_block)
353 continue
354
355 if line.startswith('decay'):
356 if not self.has_block('decay'):
357 cur_block = Block('decay')
358 self.append(cur_block)
359 else:
360 cur_block = self['decay']
361 param = Parameter()
362 param.set_block(cur_block.name)
363 param.load_str(line[6:])
364 cur_block.append(param)
365 continue
366
367 if line.startswith('xsection') or cur_block == 'notparsed':
368 cur_block = 'notparsed'
369 self.not_parsed_entry.append(line)
370 continue
371
372
373 if cur_block is None:
374 continue
375
376 if cur_block.name == 'decay':
377
378 id = cur_block[-1].lhacode[0]
379 cur_block = Block('decay_table_%s' % id)
380 self['decay'].decay_table[id] = cur_block
381
382 if cur_block.name.startswith('decay_table'):
383 param = Parameter()
384 param.load_decay(line)
385 try:
386 cur_block.append(param)
387 except InvalidParamCard:
388 pass
389 else:
390 param = Parameter()
391 param.set_block(cur_block.name)
392 param.load_str(line)
393 cur_block.append(param)
394
395 return self
396
400
403
405 """ Analyzes the comment of the parameter in the param_card and returns
406 a dictionary with parameter names in values and the tuple (lhablock, id)
407 in value as well as a dictionary for restricted values.
408 WARNING: THIS FUNCTION RELIES ON THE FORMATTING OF THE COMMENT IN THE
409 CARD TO FETCH THE PARAMETER NAME. This is mostly ok on the *_default.dat
410 but typically dangerous on the user-defined card."""
411
412 pname2block = {}
413 restricted_value = {}
414
415 for bname, block in self.items():
416 for lha_id, param in block.param_dict.items():
417 all_var = []
418 comment = param.comment
419
420 if comment.strip().startswith('set of param :'):
421 all_var = list(re.findall(r'''[^-]1\*(\w*)\b''', comment))
422
423 elif len(comment.split()) == 1:
424 all_var = [comment.strip().lower()]
425
426 else:
427 split = comment.split()
428 if len(split) >2 and split[1] == ':':
429
430 restricted_value[(bname, lha_id)] = ' '.join(split[1:])
431 elif len(split) == 2:
432 if re.search(r'''\[[A-Z]\]eV\^''', split[1]):
433 all_var = [comment.strip().lower()]
434 elif len(split) >=2 and split[1].startswith('('):
435 all_var = [split[0].strip().lower()]
436 else:
437 if not bname.startswith('qnumbers'):
438 logger.debug("not recognize information for %s %s : %s",
439 bname, lha_id, comment)
440
441 continue
442
443 for var in all_var:
444 var = var.lower()
445 if var in pname2block:
446 pname2block[var].append((bname, lha_id))
447 else:
448 pname2block[var] = [(bname, lha_id)]
449
450 return pname2block, restricted_value
451
453 """update the parameter of the card which are not free parameter
454 (i.e mass and width)
455 loglevel can be: None
456 info
457 warning
458 crash # raise an error
459 return if the param_card was modified or not
460 """
461 modify = False
462 if isinstance(restrict_rule, str):
463 restrict_rule = ParamCardRule(restrict_rule)
464
465
466 if restrict_rule:
467 _, modify = restrict_rule.check_param_card(self, modify=True, log=loglevel)
468
469 import models.model_reader as model_reader
470 import madgraph.core.base_objects as base_objects
471 if not isinstance(model, model_reader.ModelReader):
472 model = model_reader.ModelReader(model)
473 parameters = model.set_parameters_and_couplings(self)
474 else:
475 parameters = model.set_parameters_and_couplings(self)
476
477
478 for particle in model.get('particles'):
479 if particle.get('goldstone') or particle.get('ghost'):
480 continue
481 mass = model.get_parameter(particle.get('mass'))
482 lhacode = abs(particle.get_pdg_code())
483
484 if isinstance(mass, base_objects.ModelVariable) and not isinstance(mass, base_objects.ParamCardVariable):
485 try:
486 param_value = self.get('mass').get(lhacode).value
487 except Exception:
488 param = Parameter(block='mass', lhacode=(lhacode,),value=0,comment='added')
489 param_value = -999.999
490 self.get('mass').append(param)
491 model_value = parameters[particle.get('mass')]
492 if isinstance(model_value, complex):
493 if model_value.imag > 1e-5 * model_value.real:
494 raise Exception("Mass should be real number: particle %s (%s) has mass: %s" % (lhacode, particle.get('name'), model_value))
495 model_value = model_value.real
496
497 if not misc.equal(model_value, param_value, 4):
498 modify = True
499 if loglevel == 20:
500 logger.info('For consistency, the mass of particle %s (%s) is changed to %s.' % (lhacode, particle.get('name'), model_value), '$MG:BOLD')
501 else:
502 logger.log(loglevel, 'For consistency, the mass of particle %s (%s) is changed to %s.' % (lhacode, particle.get('name'), model_value))
503
504 if model_value != param_value:
505 self.get('mass').get(abs(particle.get_pdg_code())).value = model_value
506
507 width = model.get_parameter(particle.get('width'))
508 if isinstance(width, base_objects.ModelVariable):
509 try:
510 param_value = self.get('decay').get(lhacode).value
511 except Exception:
512 param = Parameter(block='decay', lhacode=(lhacode,),value=0,comment='added')
513 param_value = -999.999
514 self.get('decay').append(param)
515 model_value = parameters[particle.get('width')]
516 if isinstance(model_value, complex):
517 if model_value.imag > 1e-5 * model_value.real:
518 raise Exception("Width should be real number: particle %s (%s) has mass: %s")
519 model_value = model_value.real
520 if not misc.equal(abs(model_value), param_value, 4):
521 modify = True
522 if loglevel == 20:
523 logger.info('For consistency, the width of particle %s (%s) is changed to %s.' % (lhacode, particle.get('name'), model_value), '$MG:BOLD')
524 else:
525 logger.log(loglevel,'For consistency, the width of particle %s (%s) is changed to %s.' % (lhacode, particle.get('name'), model_value))
526
527 if abs(model_value) != param_value:
528 self.get('decay').get(abs(particle.get_pdg_code())).value = abs(model_value)
529
530 return modify
531
532
533 - def write(self, outpath=None, precision=''):
534 """schedular for writing a card"""
535
536
537 blocks = self.order_block()
538 text = self.header
539 text += ''.join([block.__str__(precision) for block in blocks])
540 text += '\n'
541 text += '\n'.join(self.not_parsed_entry)
542 if not outpath:
543 return text
544 elif isinstance(outpath, str):
545 open(outpath,'w').write(text)
546 else:
547 outpath.write(text)
548
550 """return a text file allowing to pass from this card to the new one
551 via the set command"""
552
553 diff = ''
554 for blockname, block in self.items():
555 for param in block:
556 lhacode = param.lhacode
557 value = param.value
558 new_value = new_card[blockname].get(lhacode).value
559 if not misc.equal(value, new_value, 6, zero_limit=False):
560 lhacode = ' '.join([str(i) for i in lhacode])
561 diff += 'set param_card %s %s %s # orig: %s\n' % \
562 (blockname, lhacode , new_value, value)
563 return diff
564
565
566 - def get_value(self, blockname, lhecode, default=None):
567 try:
568 return self[blockname].get(lhecode).value
569 except KeyError:
570 if blockname == 'width':
571 blockname = 'decay'
572 return self.get_value(blockname, lhecode,default=default)
573 elif default is not None:
574 return default
575 raise
576
578 """ """
579 missing = set()
580 all_blocks = set(self.keys())
581 for line in open(identpath):
582 if line.startswith('c ') or line.startswith('ccccc'):
583 continue
584 split = line.split()
585 if len(split) < 3:
586 continue
587 block = split[0]
588 if block not in self:
589 missing.add(block)
590 elif block in all_blocks:
591 all_blocks.remove(block)
592
593 unknow = all_blocks
594 return missing, unknow
595
597
598 missing_set, unknow_set = self.get_missing_block(identpath)
599
600 apply_conversion = []
601 if missing_set == set(['fralpha']) and 'alpha' in unknow_set:
602 apply_conversion.append('alpha')
603 elif all([b in missing_set for b in ['te','msl2','dsqmix','tu','selmix','msu2','msq2','usqmix','td', 'mse2','msd2']]) and\
604 all(b in unknow_set for b in ['ae','ad','sbotmix','au','modsel','staumix','stopmix']):
605 apply_conversion.append('to_slha2')
606
607 if 'to_slha2' in apply_conversion:
608 logger.error('Convention for the param_card seems to be wrong. Trying to automatically convert your file to SLHA2 format. \n'+\
609 "Please check that the conversion occurs as expected (The converter is not fully general)")
610
611 param_card =self.input_path
612 convert_to_mg5card(param_card, writting=True)
613 self.clear()
614 self.__init__(param_card)
615
616 if 'alpha' in apply_conversion:
617 logger.info("Missing block fralpha but found a block alpha, apply automatic conversion")
618 self.rename_blocks({'alpha':'fralpha'})
619 self['fralpha'].rename_keys({(): (1,)})
620 self.write(param_card.input_path)
621
622 - def write_inc_file(self, outpath, identpath, default, need_mp=False):
623 """ write a fortran file which hardcode the param value"""
624
625 self.secure_slha2(identpath)
626
627
628 fout = file_writers.FortranWriter(outpath)
629 defaultcard = ParamCard(default)
630 for line in open(identpath):
631 if line.startswith('c ') or line.startswith('ccccc'):
632 continue
633 split = line.split()
634 if len(split) < 3:
635 continue
636 block = split[0]
637 lhaid = [int(i) for i in split[1:-1]]
638 variable = split[-1]
639 if block in self:
640 try:
641 value = self[block].get(tuple(lhaid)).value
642 except KeyError:
643 value =defaultcard[block].get(tuple(lhaid)).value
644 logger.warning('information about \"%s %s" is missing using default value: %s.' %\
645 (block, lhaid, value))
646 else:
647 value =defaultcard[block].get(tuple(lhaid)).value
648 if block != 'loop':
649 logger.warning('information about \"%s %s" is missing (full block missing) using default value: %s.' %\
650 (block, lhaid, value))
651 value = str(value).lower()
652
653 if block == 'decay':
654 if self['mass'].get(tuple(lhaid)).value < 0:
655 value = '-%s' % value
656
657 fout.writelines(' %s = %s' % (variable, ('%e'%float(value)).replace('e','d')))
658 if need_mp:
659 fout.writelines(' mp__%s = %s_16' % (variable, value))
660
662 """ Convert this param_card to the convention used for the complex mass scheme:
663 This includes, removing the Yukawa block if present and making sure the EW input
664 scheme is (MZ, MW, aewm1). """
665
666
667 if self.has_block('yukawa'):
668
669 for lhacode in [param.lhacode for param in self['yukawa']]:
670 self.remove_param('yukawa', lhacode)
671
672
673 EW_input = {('sminputs',(1,)):None,
674 ('sminputs',(2,)):None,
675 ('mass',(23,)):None,
676 ('mass',(24,)):None}
677 for block, lhaid in EW_input.keys():
678 try:
679 EW_input[(block,lhaid)] = self[block].get(lhaid).value
680 except:
681 pass
682
683
684
685
686 internal_param = [key for key,value in EW_input.items() if value is None]
687 if len(internal_param)==0:
688
689 return
690
691 if len(internal_param)!=1:
692 raise InvalidParamCard(' The specified EW inputs has more than one'+\
693 ' unknown: [%s]'%(','.join([str(elem) for elem in internal_param])))
694
695
696 if not internal_param[0] in [('mass',(24,)), ('sminputs',(2,)),
697 ('sminputs',(1,))]:
698 raise InvalidParamCard(' The only EW input scheme currently supported'+\
699 ' are those with either the W mass or GF left internal.')
700
701
702 if internal_param[0] == ('mass',(24,)):
703 aewm1 = EW_input[('sminputs',(1,))]
704 Gf = EW_input[('sminputs',(2,))]
705 Mz = EW_input[('mass',(23,))]
706 try:
707 Mw = math.sqrt((Mz**2/2.0)+math.sqrt((Mz**4/4.0)-((
708 (1.0/aewm1)*math.pi*Mz**2)/(Gf*math.sqrt(2.0)))))
709 except:
710 InvalidParamCard, 'The EW inputs 1/a_ew=%f, Gf=%f, Mz=%f are inconsistent'%\
711 (aewm1,Gf,Mz)
712 self.remove_param('sminputs', (2,))
713 self.add_param('mass', (24,), Mw, 'MW')
714
716 """add an object to this"""
717
718 assert isinstance(obj, Block)
719 self[obj.name] = obj
720 if not obj.name.startswith('decay_table'):
721 self.order.append(obj)
722
723
724
727
729 """ reorganize the block """
730 return self.order
731
733 """ rename the blocks """
734
735 for old_name, new_name in name_dict.items():
736 self[new_name] = self.pop(old_name)
737 self[new_name].name = new_name
738 for param in self[new_name]:
739 param.lhablock = new_name
740
742 """ remove a blocks """
743 assert len(self[name])==0
744 [self.order.pop(i) for i,b in enumerate(self.order) if b.name == name]
745 self.pop(name)
746
748 """ remove a parameter """
749 if self.has_param(block, lhacode):
750 self[block].remove(lhacode)
751 if len(self[block]) == 0:
752 self.remove_block(block)
753
755 """check if param exists"""
756
757 try:
758 self[block].get(lhacode)
759 except:
760 return False
761 else:
762 return True
763
764 - def copy_param(self,old_block, old_lha, block=None, lhacode=None):
765 """ make a parameter, a symbolic link on another one """
766
767
768 old_block_obj = self[old_block]
769 parameter = old_block_obj.get(old_lha)
770 if not block:
771 block = old_block
772 if not lhacode:
773 lhacode = old_lha
774
775 self.add_param(block, lhacode, parameter.value, parameter.comment)
776
777 - def add_param(self,block, lha, value, comment=''):
778
779 parameter = Parameter(block=block, lhacode=lha, value=value,
780 comment=comment)
781 try:
782 new_block = self[block]
783 except KeyError:
784
785 new_block = Block(block)
786 self.append(new_block)
787 new_block.append(parameter)
788
789 - def do_help(self, block, lhacode, default=None):
790
791 if not lhacode:
792 logger.info("Information on block parameter %s:" % block, '$MG:color:BLUE')
793 print(str(self[block]))
794 elif default:
795 pname2block, restricted = default.analyze_param_card()
796 if (block, lhacode) in restricted:
797 logger.warning("This parameter will not be consider by MG5_aMC")
798 print( " MadGraph will use the following formula:")
799 print(restricted[(block, lhacode)])
800 print( " Note that some code (MadSpin/Pythia/...) will read directly the value")
801 else:
802 for name, values in pname2block.items():
803 if (block, lhacode) in values:
804 valid_name = name
805 break
806 logger.info("Information for parameter %s of the param_card" % valid_name, '$MG:color:BLUE')
807 print(("Part of Block \"%s\" with identification number %s" % (block, lhacode)))
808 print(("Current value: %s" % self[block].get(lhacode).value))
809 print(("Default value: %s" % default[block].get(lhacode).value))
810 print(("comment present in the cards: %s " % default[block].get(lhacode).comment))
811
812
813
814
815 - def mod_param(self, old_block, old_lha, block=None, lhacode=None,
816 value=None, comment=None):
817 """ change a parameter to a new one. This is not a duplication."""
818
819
820 old_block = self[old_block]
821 try:
822 parameter = old_block.get(old_lha)
823 except:
824 if lhacode is not None:
825 lhacode=old_lha
826 self.add_param(block, lhacode, value, comment)
827 return
828
829
830
831 if block:
832 parameter.lhablock = block
833 if lhacode:
834 parameter.lhacode = lhacode
835 if value:
836 parameter.value = value
837 if comment:
838 parameter.comment = comment
839
840
841 if block:
842 old_block.remove(old_lha)
843 if not len(old_block):
844 self.remove_block(old_block.name)
845 try:
846 new_block = self[block]
847 except KeyError:
848
849 new_block = Block(block)
850 self.append(new_block)
851 new_block.append(parameter)
852 elif lhacode:
853 old_block.param_dict[tuple(lhacode)] = \
854 old_block.param_dict.pop(tuple(old_lha))
855
856
858 """ check that the value is coherent and remove it"""
859
860 if self.has_param(block, lhacode):
861 param = self[block].get(lhacode)
862 if param.value != value:
863 error_msg = 'This card is not suitable to be convert to SLAH1\n'
864 error_msg += 'Parameter %s %s should be %s' % (block, lhacode, value)
865 raise InvalidParamCard(error_msg)
866 self.remove_param(block, lhacode)
867
870 """ a param Card: list of Block with also MP definition of variables"""
871
873 """ write a fortran file which hardcode the param value"""
874
875 fout = file_writers.FortranWriter(outpath)
876 defaultcard = ParamCard(default)
877 for line in open(identpath):
878 if line.startswith('c ') or line.startswith('ccccc'):
879 continue
880 split = line.split()
881 if len(split) < 3:
882 continue
883 block = split[0]
884 lhaid = [int(i) for i in split[1:-1]]
885 variable = split[-1]
886 if block in self:
887 try:
888 value = self[block].get(tuple(lhaid)).value
889 except KeyError:
890 value =defaultcard[block].get(tuple(lhaid)).value
891 else:
892 value =defaultcard[block].get(tuple(lhaid)).value
893
894 fout.writelines(' %s = %s' % (variable, ('%e' % value).replace('e','d')))
895 fout.writelines(' %s%s = %s_16' % (self.mp_prefix,
896 variable, ('%e' % value)))
897
902 """A class keeping track of the scan: flag in the param_card and
903 having an __iter__() function to scan over all the points of the scan.
904 """
905
906 logging = True
912
914 """generate the next param_card (in a abstract way) related to the scan.
915 Technically this generates only the generator."""
916
917 if hasattr(self, 'iterator'):
918 return self.iterator
919 self.iterator = self.iterate()
920 return self.iterator
921
922 - def next(self, autostart=False):
923 """call the next iteration value"""
924 try:
925 iterator = self.iterator
926 except:
927 if autostart:
928 iterator = self.__iter__()
929 else:
930 raise
931 try:
932 out = next(iterator)
933 except StopIteration:
934 del self.iterator
935 raise
936 return out
937
939 """create the actual generator"""
940 all_iterators = {}
941 pattern = re.compile(r'''scan\s*(?P<id>\d*)\s*:\s*(?P<value>[^#]*)''', re.I)
942 self.autowidth = []
943
944
945 for block in self.order:
946 for param in block:
947 if isinstance(param.value, str) and param.value.strip().lower().startswith('scan'):
948 try:
949 key, def_list = pattern.findall(param.value)[0]
950 except:
951 raise Exception("Fail to handle scanning tag: Please check that the syntax is valid")
952 if key == '':
953 key = -1 * len(all_iterators)
954 if key not in all_iterators:
955 all_iterators[key] = []
956 try:
957 all_iterators[key].append( (param, eval(def_list)))
958 except SyntaxError as error:
959 raise Exception("Fail to handle your scan definition. Please check your syntax:\n entry: %s \n Error reported: %s" %(def_list, error))
960 elif isinstance(param.value, str) and param.value.strip().lower().startswith('auto'):
961 self.autowidth.append(param)
962 keys = list(all_iterators.keys())
963 param_card = ParamCard(self)
964
965 for key in keys:
966 for param, values in all_iterators[key]:
967 self.param_order.append("%s#%s" % (param.lhablock, '_'.join(repr(i) for i in param.lhacode)))
968
969
970 lengths = [list(range(len(all_iterators[key][0][1]))) for key in keys]
971 for positions in itertools.product(*lengths):
972 self.itertag = []
973 if self.logging:
974 logger.info("Create the next param_card in the scan definition", '$MG:BOLD')
975 for i, pos in enumerate(positions):
976 key = keys[i]
977 for param, values in all_iterators[key]:
978
979 param_card[param.lhablock].get(param.lhacode).value = values[pos]
980 self.itertag.append(values[pos])
981 if self.logging:
982 logger.info("change parameter %s with code %s to %s", \
983 param.lhablock, param.lhacode, values[pos])
984
985
986
987 yield param_card
988
989
990 - def store_entry(self, run_name, cross, error=None, param_card_path=None):
991 """store the value of the cross-section"""
992
993 if isinstance(cross, dict):
994 info = dict(cross)
995 info.update({'bench' : self.itertag, 'run_name': run_name})
996 self.cross.append(info)
997 else:
998 if error is None:
999 self.cross.append({'bench' : self.itertag, 'run_name': run_name, 'cross(pb)':cross})
1000 else:
1001 self.cross.append({'bench' : self.itertag, 'run_name': run_name, 'cross(pb)':cross, 'error(pb)':error})
1002
1003 if self.autowidth and param_card_path:
1004 paramcard = ParamCard(param_card_path)
1005 for param in self.autowidth:
1006 self.cross[-1]['width#%s' % param.lhacode[0]] = paramcard.get_value(param.lhablock, param.lhacode)
1007
1008
1009 - def write_summary(self, path, order=None, lastline=False, nbcol=20):
1010 """ """
1011
1012 if path:
1013 ff = open(path, 'w')
1014 else:
1015 ff = StringIO.StringIO()
1016 if order:
1017 keys = order
1018 else:
1019 keys = list(self.cross[0].keys())
1020 if 'bench' in keys: keys.remove('bench')
1021 if 'run_name' in keys: keys.remove('run_name')
1022 keys.sort()
1023 if 'cross(pb)' in keys:
1024 keys.remove('cross(pb)')
1025 keys.append('cross(pb)')
1026 if 'error(pb)' in keys:
1027 keys.remove('error(pb)')
1028 keys.append('error(pb)')
1029
1030 formatting = "#%s%s%s\n" %('%%-%is ' % (nbcol-1), ('%%-%is ' % (nbcol))* len(self.param_order),
1031 ('%%-%is ' % (nbcol))* len(keys))
1032
1033 if not lastline:
1034 ff.write(formatting % tuple(['run_name'] + self.param_order + keys))
1035 formatting = "%s%s%s\n" %('%%-%is ' % (nbcol), ('%%-%ie ' % (nbcol))* len(self.param_order),
1036 ('%%-%ie ' % (nbcol))* len(keys))
1037
1038
1039 if not lastline:
1040 to_print = self.cross
1041 else:
1042 to_print = self.cross[-1:]
1043
1044 for info in to_print:
1045 name = info['run_name']
1046 bench = info['bench']
1047 data = []
1048 for k in keys:
1049 if k in info:
1050 data.append(info[k])
1051 else:
1052 data.append(0.)
1053 ff.write(formatting % tuple([name] + bench + data))
1054
1055 if not path:
1056 return ff.getvalue()
1057
1058
1060 """returns a smart name for the next run"""
1061
1062 if '_' in run_name:
1063 name, value = run_name.rsplit('_',1)
1064 if value.isdigit():
1065 return '%s_%02i' % (name, float(value)+1)
1066
1067 return '%s_scan_02' % run_name
1068
1072 """ A class for storing the linked between the different parameter of
1073 the param_card.
1074 Able to write a file 'param_card_rule.dat'
1075 Able to read a file 'param_card_rule.dat'
1076 Able to check the validity of a param_card.dat
1077 """
1078
1079
1081 """initialize an object """
1082
1083
1084 self.zero = []
1085 self.one = []
1086 self.identical = []
1087 self.opposite = []
1088
1089
1090 self.rule = []
1091
1092 if inputpath:
1093 self.load_rule(inputpath)
1094
1095 - def add_zero(self, lhablock, lhacode, comment=''):
1096 """add a zero rule"""
1097 self.zero.append( (lhablock, lhacode, comment) )
1098
1099 - def add_one(self, lhablock, lhacode, comment=''):
1100 """add a one rule"""
1101 self.one.append( (lhablock, lhacode, comment) )
1102
1103 - def add_identical(self, lhablock, lhacode, lhacode2, comment=''):
1104 """add a rule for identical value"""
1105 self.identical.append( (lhablock, lhacode, lhacode2, comment) )
1106
1107 - def add_opposite(self, lhablock, lhacode, lhacode2, comment=''):
1108 """add a rule for identical value"""
1109 self.opposite.append( (lhablock, lhacode, lhacode2, comment) )
1110
1111
1112 - def add_rule(self, lhablock, lhacode, rule, comment=''):
1113 """add a rule for constraint value"""
1114 self.rule.append( (lhablock, lhacode, rule) )
1115
1117
1118 text = """<file>######################################################################
1119 ## VALIDITY RULE FOR THE PARAM_CARD ####
1120 ######################################################################\n"""
1121
1122
1123 text +='<zero>\n'
1124 for name, id, comment in self.zero:
1125 text+=' %s %s # %s\n' % (name, ' '.join([str(i) for i in id]),
1126 comment)
1127
1128 text +='</zero>\n<one>\n'
1129 for name, id, comment in self.one:
1130 text+=' %s %s # %s\n' % (name, ' '.join([str(i) for i in id]),
1131 comment)
1132
1133 text +='</one>\n<identical>\n'
1134 for name, id,id2, comment in self.identical:
1135 text+=' %s %s : %s # %s\n' % (name, ' '.join([str(i) for i in id]),
1136 ' '.join([str(i) for i in id2]), comment)
1137
1138
1139 text +='</identical>\n<opposite>\n'
1140 for name, id,id2, comment in self.opposite:
1141 text+=' %s %s : %s # %s\n' % (name, ' '.join([str(i) for i in id]),
1142 ' '.join([str(i) for i in id2]), comment)
1143
1144
1145 text += '</opposite>\n<constraint>\n'
1146 for name, id, rule, comment in self.rule:
1147 text += ' %s %s : %s # %s\n' % (name, ' '.join([str(i) for i in id]),
1148 rule, comment)
1149 text += '</constraint>\n</file>'
1150
1151 if isinstance(output, str):
1152 output = open(output,'w')
1153 if hasattr(output, 'write'):
1154 output.write(text)
1155 return text
1156
1158 """ import a validity rule file """
1159
1160
1161 try:
1162 tree = ET.parse(inputpath)
1163 except IOError:
1164 if '\n' in inputpath:
1165
1166 tree = ET.fromstring(inputpath)
1167 else:
1168 raise
1169
1170
1171 element = tree.find('zero')
1172 if element is not None:
1173 for line in element.text.split('\n'):
1174 line = line.split('#',1)[0]
1175 if not line:
1176 continue
1177 lhacode = line.split()
1178 blockname = lhacode.pop(0)
1179 lhacode = [int(code) for code in lhacode ]
1180 self.add_zero(blockname, lhacode, '')
1181
1182
1183 element = tree.find('one')
1184 if element is not None:
1185 for line in element.text.split('\n'):
1186 line = line.split('#',1)[0]
1187 if not line:
1188 continue
1189 lhacode = line.split()
1190 blockname = lhacode.pop(0)
1191 lhacode = [int(code) for code in lhacode ]
1192 self.add_one(blockname, lhacode, '')
1193
1194
1195 element = tree.find('identical')
1196 if element is not None:
1197 for line in element.text.split('\n'):
1198 line = line.split('#',1)[0]
1199 if not line:
1200 continue
1201 line, lhacode2 = line.split(':')
1202 lhacode = line.split()
1203 blockname = lhacode.pop(0)
1204 lhacode = [int(code) for code in lhacode ]
1205 lhacode2 = [int(code) for code in lhacode2.split() ]
1206 self.add_identical(blockname, lhacode, lhacode2, '')
1207
1208
1209 element = tree.find('opposite')
1210 if element is not None:
1211 for line in element.text.split('\n'):
1212 line = line.split('#',1)[0]
1213 if not line:
1214 continue
1215 line, lhacode2 = line.split(':')
1216 lhacode = line.split()
1217 blockname = lhacode.pop(0)
1218 lhacode = [int(code) for code in lhacode ]
1219 lhacode2 = [int(code) for code in lhacode2.split() ]
1220 self.add_opposite(blockname, lhacode, lhacode2, '')
1221
1222
1223 element = tree.find('rule')
1224 if element is not None:
1225 for line in element.text.split('\n'):
1226 line = line.split('#',1)[0]
1227 if not line:
1228 continue
1229 line, rule = line.split(':')
1230 lhacode = line.split()
1231 blockname = lhacode.pop(0)
1232 self.add_rule(blockname, lhacode, rule, '')
1233
1234 @staticmethod
1236 """ read a param_card and return a dictionary with the associated value."""
1237
1238 output = ParamCard(path)
1239
1240
1241
1242 return output
1243
1244 @staticmethod
1256
1257
1258 - def check_param_card(self, path, modify=False, write_missing=False, log=False):
1259 """Check that the restriction card are applied"""
1260
1261 is_modified = False
1262
1263 if isinstance(path,str):
1264 card = self.read_param_card(path)
1265 else:
1266 card = path
1267
1268
1269 for block, id, comment in self.zero:
1270 try:
1271 value = float(card[block].get(id).value)
1272 except KeyError:
1273 if modify and write_missing:
1274 new_param = Parameter(block=block,lhacode=id, value=0,
1275 comment='fixed by the model')
1276 if block in card:
1277 card[block].append(new_param)
1278 else:
1279 new_block = Block(block)
1280 card.append(new_block)
1281 new_block.append(new_param)
1282 else:
1283 if value != 0:
1284 if not modify:
1285 raise InvalidParamCard('parameter %s: %s is not at zero' % \
1286 (block, ' '.join([str(i) for i in id])))
1287 else:
1288 param = card[block].get(id)
1289 param.value = 0.0
1290 param.comment += ' fixed by the model'
1291 is_modified = True
1292 if log ==20:
1293 logger.log(log,'For model consistency, update %s with id %s to value %s',
1294 block, id, 0.0, '$MG:BOLD')
1295 elif log:
1296 logger.log(log,'For model consistency, update %s with id %s to value %s',
1297 block, id, 0.0)
1298
1299
1300 for block, id, comment in self.one:
1301 try:
1302 value = card[block].get(id).value
1303 except KeyError:
1304 if modify and write_missing:
1305 new_param = Parameter(block=block,lhacode=id, value=1,
1306 comment='fixed by the model')
1307 if block in card:
1308 card[block].append(new_param)
1309 else:
1310 new_block = Block(block)
1311 card.append(new_block)
1312 new_block.append(new_param)
1313 else:
1314 if value != 1:
1315 if not modify:
1316 raise InvalidParamCard('parameter %s: %s is not at one but at %s' % \
1317 (block, ' '.join([str(i) for i in id]), value))
1318 else:
1319 param = card[block].get(id)
1320 param.value = 1.0
1321 param.comment += ' fixed by the model'
1322 is_modified = True
1323 if log ==20:
1324 logger.log(log,'For model consistency, update %s with id %s to value %s',
1325 (block, id, 1.0), '$MG:BOLD')
1326 elif log:
1327 logger.log(log,'For model consistency, update %s with id %s to value %s' %
1328 (block, id, 1.0))
1329
1330
1331
1332 for block, id1, id2, comment in self.identical:
1333 if block not in card:
1334 is_modified = True
1335 logger.warning('''Param card is not complete: Block %s is simply missing.
1336 We will use model default for all missing value! Please cross-check that
1337 this correspond to your expectation.''' % block)
1338 continue
1339 value2 = float(card[block].get(id2).value)
1340 try:
1341 param = card[block].get(id1)
1342 except KeyError:
1343 if modify and write_missing:
1344 new_param = Parameter(block=block,lhacode=id1, value=value2,
1345 comment='must be identical to %s' %id2)
1346 card[block].append(new_param)
1347 else:
1348 value1 = float(param.value)
1349
1350 if value1 != value2:
1351 if not modify:
1352 raise InvalidParamCard('parameter %s: %s is not to identical to parameter %s' % \
1353 (block, ' '.join([str(i) for i in id1]),
1354 ' '.join([str(i) for i in id2])))
1355 else:
1356 param = card[block].get(id1)
1357 param.value = value2
1358 param.comment += ' must be identical to %s' % id2
1359 is_modified = True
1360 if log ==20:
1361 logger.log(log,'For model consistency, update %s with id %s to value %s since it should be equal to parameter with id %s',
1362 block, id1, value2, id2, '$MG:BOLD')
1363 elif log:
1364 logger.log(log,'For model consistency, update %s with id %s to value %s since it should be equal to parameter with id %s',
1365 block, id1, value2, id2)
1366
1367 for block, id1, id2, comment in self.opposite:
1368 value2 = float(card[block].get(id2).value)
1369 try:
1370 param = card[block].get(id1)
1371 except KeyError:
1372 if modify and write_missing:
1373 new_param = Parameter(block=block,lhacode=id1, value=-value2,
1374 comment='must be opposite to to %s' %id2)
1375 card[block].append(new_param)
1376 else:
1377 value1 = float(param.value)
1378
1379 if value1 != -value2:
1380 if not modify:
1381 raise InvalidParamCard('parameter %s: %s is not to opposite to parameter %s' % \
1382 (block, ' '.join([str(i) for i in id1]),
1383 ' '.join([str(i) for i in id2])))
1384 else:
1385 param = card[block].get(id1)
1386 param.value = -value2
1387 param.comment += ' must be opposite to %s' % id2
1388 is_modified = True
1389 if log ==20:
1390 logger.log(log,'For model consistency, update %s with id %s to value %s since it should be equal to the opposite of the parameter with id %s',
1391 block, id1, -value2, id2, '$MG:BOLD')
1392 elif log:
1393 logger.log(log,'For model consistency, update %s with id %s to value %s since it should be equal to the opposite of the parameter with id %s',
1394 block, id1, -value2, id2)
1395
1396 return card, is_modified
1397
1400 """ """
1401
1402 if not outputpath:
1403 outputpath = path
1404 card = ParamCard(path)
1405 if not 'usqmix' in card:
1406
1407 card.write(outputpath)
1408 return
1409
1410
1411
1412 card.copy_param('mass', [6], 'sminputs', [6])
1413 card.copy_param('mass', [15], 'sminputs', [7])
1414 card.copy_param('mass', [23], 'sminputs', [4])
1415
1416
1417
1418 card.add_param('modsel',[1], value=1)
1419 card['modsel'].get([1]).format = 'int'
1420
1421
1422 scale = card['hmix'].scale
1423 if not scale:
1424 scale = 1
1425
1426
1427 if not card.has_param('sminputs', [2]):
1428 aem1 = card['sminputs'].get([1]).value
1429 mz = card['mass'].get([23]).value
1430 mw = card['mass'].get([24]).value
1431 gf = math.pi / math.sqrt(2) / aem1 * mz**2/ mw**2 /(mz**2-mw**2)
1432 card.add_param('sminputs', [2], gf, 'G_F [GeV^-2]')
1433
1434
1435 card.check_and_remove('usqmix', [1,1], 1.0)
1436 card.check_and_remove('usqmix', [2,2], 1.0)
1437 card.check_and_remove('usqmix', [4,4], 1.0)
1438 card.check_and_remove('usqmix', [5,5], 1.0)
1439 card.mod_param('usqmix', [3,3], 'stopmix', [1,1])
1440 card.mod_param('usqmix', [3,6], 'stopmix', [1,2])
1441 card.mod_param('usqmix', [6,3], 'stopmix', [2,1])
1442 card.mod_param('usqmix', [6,6], 'stopmix', [2,2])
1443
1444
1445 card.check_and_remove('dsqmix', [1,1], 1.0)
1446 card.check_and_remove('dsqmix', [2,2], 1.0)
1447 card.check_and_remove('dsqmix', [4,4], 1.0)
1448 card.check_and_remove('dsqmix', [5,5], 1.0)
1449 card.mod_param('dsqmix', [3,3], 'sbotmix', [1,1])
1450 card.mod_param('dsqmix', [3,6], 'sbotmix', [1,2])
1451 card.mod_param('dsqmix', [6,3], 'sbotmix', [2,1])
1452 card.mod_param('dsqmix', [6,6], 'sbotmix', [2,2])
1453
1454
1455
1456 card.check_and_remove('selmix', [1,1], 1.0)
1457 card.check_and_remove('selmix', [2,2], 1.0)
1458 card.check_and_remove('selmix', [4,4], 1.0)
1459 card.check_and_remove('selmix', [5,5], 1.0)
1460 card.mod_param('selmix', [3,3], 'staumix', [1,1])
1461 card.mod_param('selmix', [3,6], 'staumix', [1,2])
1462 card.mod_param('selmix', [6,3], 'staumix', [2,1])
1463 card.mod_param('selmix', [6,6], 'staumix', [2,2])
1464
1465
1466 card.mod_param('fralpha', [1], 'alpha', [' '])
1467
1468
1469 if not card.has_param('hmix', [3]):
1470 aem1 = card['sminputs'].get([1]).value
1471 tanb = card['hmix'].get([2]).value
1472 mz = card['mass'].get([23]).value
1473 mw = card['mass'].get([24]).value
1474 sw = math.sqrt(mz**2 - mw**2)/mz
1475 ee = 2 * math.sqrt(1/aem1) * math.sqrt(math.pi)
1476 vu = 2 * mw *sw /ee * math.sin(math.atan(tanb))
1477 card.add_param('hmix', [3], vu, 'higgs vev(Q) MSSM DRb')
1478 card['hmix'].scale= scale
1479
1480
1481 card.check_and_remove('vckm', [1,1], 1.0)
1482 card.check_and_remove('vckm', [2,2], 1.0)
1483 card.check_and_remove('vckm', [3,3], 1.0)
1484
1485
1486 card.check_and_remove('snumix', [1,1], 1.0)
1487 card.check_and_remove('snumix', [2,2], 1.0)
1488 card.check_and_remove('snumix', [3,3], 1.0)
1489
1490
1491 card.check_and_remove('upmns', [1,1], 1.0)
1492 card.check_and_remove('upmns', [2,2], 1.0)
1493 card.check_and_remove('upmns', [3,3], 1.0)
1494
1495
1496 ye = card['ye'].get([3, 3]).value
1497 te = card['te'].get([3, 3]).value
1498 card.mod_param('te', [3,3], 'ae', [3,3], value= te/ye, comment='A_tau(Q) DRbar')
1499 card.add_param('ae', [1,1], 0, 'A_e(Q) DRbar')
1500 card.add_param('ae', [2,2], 0, 'A_mu(Q) DRbar')
1501 card['ae'].scale = scale
1502 card['ye'].scale = scale
1503
1504
1505 yu = card['yu'].get([3, 3]).value
1506 tu = card['tu'].get([3, 3]).value
1507 card.mod_param('tu', [3,3], 'au', [3,3], value= tu/yu, comment='A_t(Q) DRbar')
1508 card.add_param('au', [1,1], 0, 'A_u(Q) DRbar')
1509 card.add_param('au', [2,2], 0, 'A_c(Q) DRbar')
1510 card['au'].scale = scale
1511 card['yu'].scale = scale
1512
1513
1514 yd = card['yd'].get([3, 3]).value
1515 td = card['td'].get([3, 3]).value
1516 if td:
1517 card.mod_param('td', [3,3], 'ad', [3,3], value= td/yd, comment='A_b(Q) DRbar')
1518 else:
1519 card.mod_param('td', [3,3], 'ad', [3,3], value= 0., comment='A_b(Q) DRbar')
1520 card.add_param('ad', [1,1], 0, 'A_d(Q) DRbar')
1521 card.add_param('ad', [2,2], 0, 'A_s(Q) DRbar')
1522 card['ad'].scale = scale
1523 card['yd'].scale = scale
1524
1525
1526 value = card['msl2'].get([1, 1]).value
1527 card.mod_param('msl2', [1,1], 'msoft', [31], math.sqrt(value))
1528 value = card['msl2'].get([2, 2]).value
1529 card.mod_param('msl2', [2,2], 'msoft', [32], math.sqrt(value))
1530 value = card['msl2'].get([3, 3]).value
1531 card.mod_param('msl2', [3,3], 'msoft', [33], math.sqrt(value))
1532 card['msoft'].scale = scale
1533
1534
1535 value = card['mse2'].get([1, 1]).value
1536 card.mod_param('mse2', [1,1], 'msoft', [34], math.sqrt(value))
1537 value = card['mse2'].get([2, 2]).value
1538 card.mod_param('mse2', [2,2], 'msoft', [35], math.sqrt(value))
1539 value = card['mse2'].get([3, 3]).value
1540 card.mod_param('mse2', [3,3], 'msoft', [36], math.sqrt(value))
1541
1542
1543 value = card['msq2'].get([1, 1]).value
1544 card.mod_param('msq2', [1,1], 'msoft', [41], math.sqrt(value))
1545 value = card['msq2'].get([2, 2]).value
1546 card.mod_param('msq2', [2,2], 'msoft', [42], math.sqrt(value))
1547 value = card['msq2'].get([3, 3]).value
1548 card.mod_param('msq2', [3,3], 'msoft', [43], math.sqrt(value))
1549
1550
1551 value = card['msu2'].get([1, 1]).value
1552 card.mod_param('msu2', [1,1], 'msoft', [44], math.sqrt(value))
1553 value = card['msu2'].get([2, 2]).value
1554 card.mod_param('msu2', [2,2], 'msoft', [45], math.sqrt(value))
1555 value = card['msu2'].get([3, 3]).value
1556 card.mod_param('msu2', [3,3], 'msoft', [46], math.sqrt(value))
1557
1558
1559 value = card['msd2'].get([1, 1]).value
1560 card.mod_param('msd2', [1,1], 'msoft', [47], math.sqrt(value))
1561 value = card['msd2'].get([2, 2]).value
1562 card.mod_param('msd2', [2,2], 'msoft', [48], math.sqrt(value))
1563 value = card['msd2'].get([3, 3]).value
1564 card.mod_param('msd2', [3,3], 'msoft', [49], math.sqrt(value))
1565
1566
1567
1568
1569
1570
1571 card.write(outputpath)
1572
1576 """
1577 """
1578
1579 if not outputpath:
1580 outputpath = path
1581 card = ParamCard(path)
1582 if 'usqmix' in card:
1583
1584 if outputpath != path and writting:
1585 card.write(outputpath)
1586 return card
1587
1588
1589
1590 card.remove_param('sminputs', [2])
1591 card.remove_param('sminputs', [4])
1592 card.remove_param('sminputs', [6])
1593 card.remove_param('sminputs', [7])
1594
1595
1596
1597 card.remove_param('modsel',[1])
1598
1599
1600
1601 card.add_param('usqmix', [1,1], 1.0)
1602 card.add_param('usqmix', [2,2], 1.0)
1603 card.add_param('usqmix', [4,4], 1.0)
1604 card.add_param('usqmix', [5,5], 1.0)
1605 card.mod_param('stopmix', [1,1], 'usqmix', [3,3])
1606 card.mod_param('stopmix', [1,2], 'usqmix', [3,6])
1607 card.mod_param('stopmix', [2,1], 'usqmix', [6,3])
1608 card.mod_param('stopmix', [2,2], 'usqmix', [6,6])
1609
1610
1611 card.add_param('dsqmix', [1,1], 1.0)
1612 card.add_param('dsqmix', [2,2], 1.0)
1613 card.add_param('dsqmix', [4,4], 1.0)
1614 card.add_param('dsqmix', [5,5], 1.0)
1615 card.mod_param('sbotmix', [1,1], 'dsqmix', [3,3])
1616 card.mod_param('sbotmix', [1,2], 'dsqmix', [3,6])
1617 card.mod_param('sbotmix', [2,1], 'dsqmix', [6,3])
1618 card.mod_param('sbotmix', [2,2], 'dsqmix', [6,6])
1619
1620
1621
1622 card.add_param('selmix', [1,1], 1.0)
1623 card.add_param('selmix', [2,2], 1.0)
1624 card.add_param('selmix', [4,4], 1.0)
1625 card.add_param('selmix', [5,5], 1.0)
1626 card.mod_param('staumix', [1,1], 'selmix', [3,3])
1627 card.mod_param('staumix', [1,2], 'selmix', [3,6])
1628 card.mod_param('staumix', [2,1], 'selmix', [6,3])
1629 card.mod_param('staumix', [2,2], 'selmix', [6,6])
1630
1631
1632 card.mod_param('alpha', [], 'fralpha', [1])
1633
1634
1635 card.remove_param('hmix', [3])
1636
1637
1638 card.add_param('vckm', [1,1], 1.0)
1639 card.add_param('vckm', [2,2], 1.0)
1640 card.add_param('vckm', [3,3], 1.0)
1641
1642
1643 card.add_param('snumix', [1,1], 1.0)
1644 card.add_param('snumix', [2,2], 1.0)
1645 card.add_param('snumix', [3,3], 1.0)
1646
1647
1648 card.add_param('upmns', [1,1], 1.0)
1649 card.add_param('upmns', [2,2], 1.0)
1650 card.add_param('upmns', [3,3], 1.0)
1651
1652
1653 ye = card['ye'].get([1, 1], default=0).value
1654 ae = card['ae'].get([1, 1], default=0).value
1655 card.mod_param('ae', [1,1], 'te', [1,1], value= ae * ye, comment='T_e(Q) DRbar')
1656 if ae * ye:
1657 raise InvalidParamCard('''This card is not suitable to be converted to MSSM UFO model
1658 Parameter ae [1, 1] times ye [1,1] should be 0''')
1659 card.remove_param('ae', [1,1])
1660
1661 ye = card['ye'].get([2, 2], default=0).value
1662
1663 ae = card['ae'].get([2, 2], default=0).value
1664 card.mod_param('ae', [2,2], 'te', [2,2], value= ae * ye, comment='T_mu(Q) DRbar')
1665 if ae * ye:
1666 raise InvalidParamCard('''This card is not suitable to be converted to MSSM UFO model
1667 Parameter ae [2, 2] times ye [2,2] should be 0''')
1668 card.remove_param('ae', [2,2])
1669
1670 ye = card['ye'].get([3, 3], default=0).value
1671 ae = card['ae'].get([3, 3], default=0).value
1672 card.mod_param('ae', [3,3], 'te', [3,3], value= ae * ye, comment='T_tau(Q) DRbar')
1673
1674
1675 yu = card['yu'].get([1, 1], default=0).value
1676 au = card['au'].get([1, 1], default=0).value
1677 card.mod_param('au', [1,1], 'tu', [1,1], value= au * yu, comment='T_u(Q) DRbar')
1678 if au * yu:
1679 raise InvalidParamCard('''This card is not suitable to be converted to MSSM UFO model
1680 Parameter au [1, 1] times yu [1,1] should be 0''')
1681 card.remove_param('au', [1,1])
1682
1683 ye = card['yu'].get([2, 2], default=0).value
1684
1685 ae = card['au'].get([2, 2], default=0).value
1686 card.mod_param('au', [2,2], 'tu', [2,2], value= au * yu, comment='T_c(Q) DRbar')
1687 if au * yu:
1688 raise InvalidParamCard('''This card is not suitable to be converted to MSSM UFO model
1689 Parameter au [2, 2] times yu [2,2] should be 0''')
1690 card.remove_param('au', [2,2])
1691
1692 yu = card['yu'].get([3, 3]).value
1693 au = card['au'].get([3, 3]).value
1694 card.mod_param('au', [3,3], 'tu', [3,3], value= au * yu, comment='T_t(Q) DRbar')
1695
1696
1697 yd = card['yd'].get([1, 1], default=0).value
1698 ad = card['ad'].get([1, 1], default=0).value
1699 card.mod_param('ad', [1,1], 'td', [1,1], value= ad * yd, comment='T_d(Q) DRbar')
1700 if ad * yd:
1701 raise InvalidParamCard('''This card is not suitable to be converted to MSSM UFO model
1702 Parameter ad [1, 1] times yd [1,1] should be 0''')
1703 card.remove_param('ad', [1,1])
1704
1705 ye = card['yd'].get([2, 2], default=0).value
1706
1707 ae = card['ad'].get([2, 2], default=0).value
1708 card.mod_param('ad', [2,2], 'td', [2,2], value= ad * yd, comment='T_s(Q) DRbar')
1709 if ad * yd:
1710 raise InvalidParamCard('''This card is not suitable to be converted to MSSM UFO model
1711 Parameter ad [2, 2] times yd [2,2] should be 0''')
1712 card.remove_param('ad', [2,2])
1713
1714 yd = card['yd'].get([3, 3]).value
1715 ad = card['ad'].get([3, 3]).value
1716 card.mod_param('ad', [3,3], 'td', [3,3], value= ad * yd, comment='T_b(Q) DRbar')
1717
1718
1719
1720 value = card['msoft'].get([31]).value
1721 card.mod_param('msoft', [31], 'msl2', [1,1], value**2)
1722 value = card['msoft'].get([32]).value
1723 card.mod_param('msoft', [32], 'msl2', [2,2], value**2)
1724 value = card['msoft'].get([33]).value
1725 card.mod_param('msoft', [33], 'msl2', [3,3], value**2)
1726
1727
1728 value = card['msoft'].get([34]).value
1729 card.mod_param('msoft', [34], 'mse2', [1,1], value**2)
1730 value = card['msoft'].get([35]).value
1731 card.mod_param('msoft', [35], 'mse2', [2,2], value**2)
1732 value = card['msoft'].get([36]).value
1733 card.mod_param('msoft', [36], 'mse2', [3,3], value**2)
1734
1735
1736 value = card['msoft'].get([41]).value
1737 card.mod_param('msoft', [41], 'msq2', [1,1], value**2)
1738 value = card['msoft'].get([42]).value
1739 card.mod_param('msoft', [42], 'msq2', [2,2], value**2)
1740 value = card['msoft'].get([43]).value
1741 card.mod_param('msoft', [43], 'msq2', [3,3], value**2)
1742
1743
1744 value = card['msoft'].get([44]).value
1745 card.mod_param('msoft', [44], 'msu2', [1,1], value**2)
1746 value = card['msoft'].get([45]).value
1747 card.mod_param('msoft', [45], 'msu2', [2,2], value**2)
1748 value = card['msoft'].get([46]).value
1749 card.mod_param('msoft', [46], 'msu2', [3,3], value**2)
1750
1751
1752 value = card['msoft'].get([47]).value
1753 card.mod_param('msoft', [47], 'msd2', [1,1], value**2)
1754 value = card['msoft'].get([48]).value
1755 card.mod_param('msoft', [48], 'msd2', [2,2], value**2)
1756 value = card['msoft'].get([49]).value
1757 card.mod_param('msoft', [49], 'msd2', [3,3], value**2)
1758
1759
1760
1761
1762 if writting:
1763 card.write(outputpath)
1764 return card
1765
1768 """ modify the current param_card such that it agrees with the restriction"""
1769
1770 if not outputpath:
1771 outputpath = path
1772
1773 cardrule = ParamCardRule()
1774 cardrule.load_rule(restrictpath)
1775 try :
1776 cardrule.check_param_card(path, modify=False)
1777 except InvalidParamCard:
1778 new_data, was_modified = cardrule.check_param_card(path, modify=True, write_missing=True)
1779 if was_modified:
1780 cardrule.write_param_card(outputpath, new_data)
1781 else:
1782 if path != outputpath:
1783 shutil.copy(path, outputpath)
1784 return cardrule
1785
1787 """ check if the current param_card agrees with the restriction"""
1788
1789 if restrictpath is None:
1790 restrictpath = os.path.dirname(path)
1791 restrictpath = os.path.join(restrictpath, os.pardir, os.pardir, 'Source',
1792 'MODEL', 'param_card_rule.dat')
1793 if not os.path.exists(restrictpath):
1794 restrictpath = os.path.dirname(path)
1795 restrictpath = os.path.join(restrictpath, os.pardir, 'Source',
1796 'MODEL', 'param_card_rule.dat')
1797 if not os.path.exists(restrictpath):
1798 return True
1799
1800 cardrule = ParamCardRule()
1801 cardrule.load_rule(restrictpath)
1802 cardrule.check_param_card(path, modify=False)
1803
1804
1805
1806 if '__main__' == __name__:
1807
1808
1809
1810
1811 import sys
1812 args = sys.argv
1813 sys.path.append(os.path.dirname(__file__))
1814 convert_to_slha1(args[1] , args[2])
1815