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