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 try:
457 param_value = self.get('mass').get(lhacode).value
458 except Exception:
459 param = Parameter(block='mass', lhacode=(lhacode,),value=0,comment='added')
460 param_value = -999.999
461 self.get('mass').append(param)
462 model_value = parameters[particle.get('mass')]
463 if isinstance(model_value, complex):
464 if model_value.imag > 1e-5 * model_value.real:
465 raise Exception, "Mass should be real number: particle %s (%s) has mass: %s" % (lhacode, particle.get('name'), model_value)
466 model_value = model_value.real
467
468 if not misc.equal(model_value, param_value, 4):
469 modify = True
470 if loglevel == 20:
471 logger.info('For consistency, the mass of particle %s (%s) is changed to %s.' % (lhacode, particle.get('name'), model_value), '$MG:color:BLACK')
472 else:
473 logger.log(loglevel, 'For consistency, the mass of particle %s (%s) is changed to %s.' % (lhacode, particle.get('name'), model_value))
474
475 if model_value != param_value:
476 self.get('mass').get(abs(particle.get_pdg_code())).value = model_value
477
478 width = model.get_parameter(particle.get('width'))
479 if isinstance(width, base_objects.ModelVariable):
480 try:
481 param_value = self.get('decay').get(lhacode).value
482 except Exception:
483 param = Parameter(block='decay', lhacode=(lhacode,),value=0,comment='added')
484 param_value = -999.999
485 self.get('decay').append(param)
486 model_value = parameters[particle.get('width')]
487 if isinstance(model_value, complex):
488 if model_value.imag > 1e-5 * model_value.real:
489 raise Exception, "Width should be real number: particle %s (%s) has mass: %s"
490 model_value = model_value.real
491 if not misc.equal(model_value, param_value, 4):
492 modify = True
493 if loglevel == 20:
494 logger.info('For consistency, the width of particle %s (%s) is changed to %s.' % (lhacode, particle.get('name'), model_value), '$MG:color:BLACK')
495 else:
496 logger.log(loglevel,'For consistency, the width of particle %s (%s) is changed to %s.' % (lhacode, particle.get('name'), model_value))
497
498 if model_value != param_value:
499 self.get('decay').get(abs(particle.get_pdg_code())).value = model_value
500
501 return modify
502
503
504 - def write(self, outpath=None, precision=''):
505 """schedular for writing a card"""
506
507
508 blocks = self.order_block()
509 text = self.header
510 text += ''.join([block.__str__(precision) for block in blocks])
511 if not outpath:
512 return text
513 elif isinstance(outpath, str):
514 file(outpath,'w').write(text)
515 else:
516 outpath.write(text)
517
519 """return a text file allowing to pass from this card to the new one
520 via the set command"""
521
522 diff = ''
523 for blockname, block in self.items():
524 for param in block:
525 lhacode = param.lhacode
526 value = param.value
527 new_value = new_card[blockname].get(lhacode).value
528 if not misc.equal(value, new_value, 6, zero_limit=False):
529 lhacode = ' '.join([str(i) for i in lhacode])
530 diff += 'set param_card %s %s %s # orig: %s\n' % \
531 (blockname, lhacode , new_value, value)
532 return diff
533
534
535 - def get_value(self, blockname, lhecode, default=None):
536 try:
537 return self[blockname].get(lhecode).value
538 except KeyError:
539 if blockname == 'width':
540 blockname = 'decay'
541 return self.get_value(blockname, lhecode,default=default)
542 elif default is not None:
543 return default
544 raise
545
546 - def write_inc_file(self, outpath, identpath, default, need_mp=False):
547 """ write a fortran file which hardcode the param value"""
548
549 fout = file_writers.FortranWriter(outpath)
550 defaultcard = ParamCard(default)
551 for line in open(identpath):
552 if line.startswith('c ') or line.startswith('ccccc'):
553 continue
554 split = line.split()
555 if len(split) < 3:
556 continue
557 block = split[0]
558 lhaid = [int(i) for i in split[1:-1]]
559 variable = split[-1]
560 if block in self:
561 try:
562 value = self[block].get(tuple(lhaid)).value
563 except KeyError:
564 value =defaultcard[block].get(tuple(lhaid)).value
565 logger.warning('information about \"%s %s" is missing using default value: %s.' %\
566 (block, lhaid, value))
567 else:
568 value =defaultcard[block].get(tuple(lhaid)).value
569 logger.warning('information about \"%s %s" is missing (full block missing) using default value: %s.' %\
570 (block, lhaid, value))
571 value = str(value).lower()
572 fout.writelines(' %s = %s' % (variable, ('%e'%float(value)).replace('e','d')))
573 if need_mp:
574 fout.writelines(' mp__%s = %s_16' % (variable, value))
575
577 """ Convert this param_card to the convention used for the complex mass scheme:
578 This includes, removing the Yukawa block if present and making sure the EW input
579 scheme is (MZ, MW, aewm1). """
580
581
582 if self.has_block('yukawa'):
583
584 for lhacode in [param.lhacode for param in self['yukawa']]:
585 self.remove_param('yukawa', lhacode)
586
587
588 EW_input = {('sminputs',(1,)):None,
589 ('sminputs',(2,)):None,
590 ('mass',(23,)):None,
591 ('mass',(24,)):None}
592 for block, lhaid in EW_input.keys():
593 try:
594 EW_input[(block,lhaid)] = self[block].get(lhaid).value
595 except:
596 pass
597
598
599
600
601 internal_param = [key for key,value in EW_input.items() if value is None]
602 if len(internal_param)==0:
603
604 return
605
606 if len(internal_param)!=1:
607 raise InvalidParamCard,' The specified EW inputs has more than one'+\
608 ' unknown: [%s]'%(','.join([str(elem) for elem in internal_param]))
609
610
611 if not internal_param[0] in [('mass',(24,)), ('sminputs',(2,)),
612 ('sminputs',(1,))]:
613 raise InvalidParamCard, ' The only EW input scheme currently supported'+\
614 ' are those with either the W mass or GF left internal.'
615
616
617 if internal_param[0] == ('mass',(24,)):
618 aewm1 = EW_input[('sminputs',(1,))]
619 Gf = EW_input[('sminputs',(2,))]
620 Mz = EW_input[('mass',(23,))]
621 try:
622 Mw = math.sqrt((Mz**2/2.0)+math.sqrt((Mz**4/4.0)-((
623 (1.0/aewm1)*math.pi*Mz**2)/(Gf*math.sqrt(2.0)))))
624 except:
625 InvalidParamCard, 'The EW inputs 1/a_ew=%f, Gf=%f, Mz=%f are inconsistent'%\
626 (aewm1,Gf,Mz)
627 self.remove_param('sminputs', (2,))
628 self.add_param('mass', (24,), Mw, 'MW')
629
631 """add an object to this"""
632
633 assert isinstance(obj, Block)
634 self[obj.name] = obj
635 if not obj.name.startswith('decay_table'):
636 self.order.append(obj)
637
638
639
641 return self.has_key(name)
642
644 """ reorganize the block """
645 return self.order
646
648 """ rename the blocks """
649
650 for old_name, new_name in name_dict.items():
651 self[new_name] = self.pop(old_name)
652 self[new_name].name = new_name
653 for param in self[new_name]:
654 param.lhablock = new_name
655
657 """ remove a blocks """
658 assert len(self[name])==0
659 [self.order.pop(i) for i,b in enumerate(self.order) if b.name == name]
660 self.pop(name)
661
663 """ remove a parameter """
664 if self.has_param(block, lhacode):
665 self[block].remove(lhacode)
666 if len(self[block]) == 0:
667 self.remove_block(block)
668
670 """check if param exists"""
671
672 try:
673 self[block].get(lhacode)
674 except:
675 return False
676 else:
677 return True
678
679 - def copy_param(self,old_block, old_lha, block=None, lhacode=None):
680 """ make a parameter, a symbolic link on another one """
681
682
683 old_block_obj = self[old_block]
684 parameter = old_block_obj.get(old_lha)
685 if not block:
686 block = old_block
687 if not lhacode:
688 lhacode = old_lha
689
690 self.add_param(block, lhacode, parameter.value, parameter.comment)
691
692 - def add_param(self,block, lha, value, comment=''):
693
694 parameter = Parameter(block=block, lhacode=lha, value=value,
695 comment=comment)
696 try:
697 new_block = self[block]
698 except KeyError:
699
700 new_block = Block(block)
701 self.append(new_block)
702 new_block.append(parameter)
703
704 - def do_help(self, block, lhacode, default=None):
705
706 if not lhacode:
707 logger.info("Information on block parameter %s:" % block, '$MG:color:BLUE')
708 print str(self[block])
709 elif default:
710 pname2block, restricted = default.analyze_param_card()
711 if (block, lhacode) in restricted:
712 logger.warning("This parameter will not be consider by MG5_aMC")
713 print( " MadGraph will use the following formula:")
714 print restricted[(block, lhacode)]
715 print( " Note that some code (MadSpin/Pythia/...) will read directly the value")
716 else:
717 for name, values in pname2block.items():
718 if (block, lhacode) in values:
719 valid_name = name
720 break
721 logger.info("Information for parameter %s of the param_card" % valid_name, '$MG:color:BLUE')
722 print("Part of Block \"%s\" with identification number %s" % (block, lhacode))
723 print("Current value: %s" % self[block].get(lhacode).value)
724 print("Default value: %s" % default[block].get(lhacode).value)
725 print("comment present in the cards: %s " % default[block].get(lhacode).comment)
726
727
728
729
730 - def mod_param(self, old_block, old_lha, block=None, lhacode=None,
731 value=None, comment=None):
732 """ change a parameter to a new one. This is not a duplication."""
733
734
735 old_block = self[old_block]
736 try:
737 parameter = old_block.get(old_lha)
738 except:
739 if lhacode is not None:
740 lhacode=old_lha
741 self.add_param(block, lhacode, value, comment)
742 return
743
744
745
746 if block:
747 parameter.lhablock = block
748 if lhacode:
749 parameter.lhacode = lhacode
750 if value:
751 parameter.value = value
752 if comment:
753 parameter.comment = comment
754
755
756 if block:
757 old_block.remove(old_lha)
758 if not len(old_block):
759 self.remove_block(old_block.name)
760 try:
761 new_block = self[block]
762 except KeyError:
763
764 new_block = Block(block)
765 self.append(new_block)
766 new_block.append(parameter)
767 elif lhacode:
768 old_block.param_dict[tuple(lhacode)] = \
769 old_block.param_dict.pop(tuple(old_lha))
770
771
773 """ check that the value is coherent and remove it"""
774
775 if self.has_param(block, lhacode):
776 param = self[block].get(lhacode)
777 if param.value != value:
778 error_msg = 'This card is not suitable to be convert to SLAH1\n'
779 error_msg += 'Parameter %s %s should be %s' % (block, lhacode, value)
780 raise InvalidParamCard, error_msg
781 self.remove_param(block, lhacode)
782
785 """ a param Card: list of Block with also MP definition of variables"""
786
788 """ write a fortran file which hardcode the param value"""
789
790 fout = file_writers.FortranWriter(outpath)
791 defaultcard = ParamCard(default)
792 for line in open(identpath):
793 if line.startswith('c ') or line.startswith('ccccc'):
794 continue
795 split = line.split()
796 if len(split) < 3:
797 continue
798 block = split[0]
799 lhaid = [int(i) for i in split[1:-1]]
800 variable = split[-1]
801 if block in self:
802 try:
803 value = self[block].get(tuple(lhaid)).value
804 except KeyError:
805 value =defaultcard[block].get(tuple(lhaid)).value
806 else:
807 value =defaultcard[block].get(tuple(lhaid)).value
808
809 fout.writelines(' %s = %s' % (variable, ('%e' % value).replace('e','d')))
810 fout.writelines(' %s%s = %s_16' % (self.mp_prefix,
811 variable, ('%e' % value)))
812
816 """A class keeping track of the scan: flag in the param_card and
817 having an __iter__() function to scan over all the points of the scan.
818 """
819
820 logging = True
826
828 """generate the next param_card (in a abstract way) related to the scan.
829 Technically this generates only the generator."""
830
831 if hasattr(self, 'iterator'):
832 return self.iterator
833 self.iterator = self.iterate()
834 return self.iterator
835
836 - def next(self, autostart=False):
837 """call the next iteration value"""
838 try:
839 iterator = self.iterator
840 except:
841 if autostart:
842 iterator = self.__iter__()
843 else:
844 raise
845 try:
846 out = iterator.next()
847 except StopIteration:
848 del self.iterator
849 raise
850 return out
851
853 """create the actual generator"""
854 all_iterators = {}
855 auto = 'Auto'
856 pattern = re.compile(r'''scan\s*(?P<id>\d*)\s*:\s*(?P<value>[^#]*)''', re.I)
857
858
859 for block in self.order:
860 for param in block:
861 if isinstance(param.value, str) and param.value.strip().lower().startswith('scan'):
862 try:
863 key, def_list = pattern.findall(param.value)[0]
864 except:
865 raise Exception, "Fail to handle scanning tag: Please check that the syntax is valid"
866 if key == '':
867 key = -1 * len(all_iterators)
868 if key not in all_iterators:
869 all_iterators[key] = []
870 try:
871 all_iterators[key].append( (param, eval(def_list)))
872 except SyntaxError, error:
873 raise Exception, "Fail to handle your scan definition. Please check your syntax:\n entry: %s \n Error reported: %s" %(def_list, error)
874
875 keys = all_iterators.keys()
876 param_card = ParamCard(self)
877
878 for key in keys:
879 for param, values in all_iterators[key]:
880 self.param_order.append("%s#%s" % (param.lhablock, '_'.join(`i` for i in param.lhacode)))
881
882
883 lengths = [range(len(all_iterators[key][0][1])) for key in keys]
884 for positions in itertools.product(*lengths):
885 self.itertag = []
886 if self.logging:
887 logger.info("Create the next param_card in the scan definition", '$MG:color:BLACK')
888 for i, pos in enumerate(positions):
889 key = keys[i]
890 for param, values in all_iterators[key]:
891
892 param_card[param.lhablock].get(param.lhacode).value = values[pos]
893 self.itertag.append(values[pos])
894 if self.logging:
895 logger.info("change parameter %s with code %s to %s", \
896 param.lhablock, param.lhacode, values[pos])
897
898
899
900 yield param_card
901
902
903 - def store_entry(self, run_name, cross):
904 """store the value of the cross-section"""
905 if isinstance(cross, dict):
906 info = dict(cross)
907 info.update({'bench' : self.itertag, 'run_name': run_name})
908 self.cross.append(info)
909 else:
910 self.cross.append({'bench' : self.itertag, 'run_name': run_name, 'cross(pb)':cross})
911
912
913 - def write_summary(self, path, order=None, lastline=False, nbcol=20):
914 """ """
915
916 if path:
917 ff = open(path, 'w')
918 else:
919 ff = StringIO.StringIO()
920 if order:
921 keys = order
922 else:
923 keys = self.cross[0].keys()
924 keys.remove('bench')
925 keys.remove('run_name')
926 keys.sort()
927
928 formatting = "#%s%s%s\n" %('%%-%is ' % (nbcol-1), ('%%-%is ' % (nbcol))* len(self.param_order),
929 ('%%-%is ' % (nbcol))* len(keys))
930
931 if not lastline:
932 ff.write(formatting % tuple(['run_name'] + self.param_order + keys))
933 formatting = "%s%s%s\n" %('%%-%is ' % (nbcol), ('%%-%ie ' % (nbcol))* len(self.param_order),
934 ('%%-%ie ' % (nbcol))* len(keys))
935
936 if not lastline:
937 to_print = self.cross
938 else:
939 to_print = self.cross[-1:]
940 for info in to_print:
941 name = info['run_name']
942 bench = info['bench']
943 data = []
944 for k in keys:
945 data.append(info[k])
946
947 ff.write(formatting % tuple([name] + bench + data))
948
949 if not path:
950 return ff.getvalue()
951
952
954 """returns a smart name for the next run"""
955
956 if '_' in run_name:
957 name, value = run_name.rsplit('_',1)
958 if value.isdigit():
959 return '%s_%02i' % (name, float(value)+1)
960
961 return '%s_scan_02' % run_name
962
965 """ A class for storing the linked between the different parameter of
966 the param_card.
967 Able to write a file 'param_card_rule.dat'
968 Able to read a file 'param_card_rule.dat'
969 Able to check the validity of a param_card.dat
970 """
971
972
974 """initialize an object """
975
976
977 self.zero = []
978 self.one = []
979 self.identical = []
980 self.opposite = []
981
982
983 self.rule = []
984
985 if inputpath:
986 self.load_rule(inputpath)
987
988 - def add_zero(self, lhablock, lhacode, comment=''):
989 """add a zero rule"""
990 self.zero.append( (lhablock, lhacode, comment) )
991
992 - def add_one(self, lhablock, lhacode, comment=''):
993 """add a one rule"""
994 self.one.append( (lhablock, lhacode, comment) )
995
996 - def add_identical(self, lhablock, lhacode, lhacode2, comment=''):
997 """add a rule for identical value"""
998 self.identical.append( (lhablock, lhacode, lhacode2, comment) )
999
1000 - def add_opposite(self, lhablock, lhacode, lhacode2, comment=''):
1001 """add a rule for identical value"""
1002 self.opposite.append( (lhablock, lhacode, lhacode2, comment) )
1003
1004
1005 - def add_rule(self, lhablock, lhacode, rule, comment=''):
1006 """add a rule for constraint value"""
1007 self.rule.append( (lhablock, lhacode, rule) )
1008
1010
1011 text = """<file>######################################################################
1012 ## VALIDITY RULE FOR THE PARAM_CARD ####
1013 ######################################################################\n"""
1014
1015
1016 text +='<zero>\n'
1017 for name, id, comment in self.zero:
1018 text+=' %s %s # %s\n' % (name, ' '.join([str(i) for i in id]),
1019 comment)
1020
1021 text +='</zero>\n<one>\n'
1022 for name, id, comment in self.one:
1023 text+=' %s %s # %s\n' % (name, ' '.join([str(i) for i in id]),
1024 comment)
1025
1026 text +='</one>\n<identical>\n'
1027 for name, id,id2, comment in self.identical:
1028 text+=' %s %s : %s # %s\n' % (name, ' '.join([str(i) for i in id]),
1029 ' '.join([str(i) for i in id2]), comment)
1030
1031
1032 text +='</identical>\n<opposite>\n'
1033 for name, id,id2, comment in self.opposite:
1034 text+=' %s %s : %s # %s\n' % (name, ' '.join([str(i) for i in id]),
1035 ' '.join([str(i) for i in id2]), comment)
1036
1037
1038 text += '</opposite>\n<constraint>\n'
1039 for name, id, rule, comment in self.rule:
1040 text += ' %s %s : %s # %s\n' % (name, ' '.join([str(i) for i in id]),
1041 rule, comment)
1042 text += '</constraint>\n</file>'
1043
1044 if isinstance(output, str):
1045 output = open(output,'w')
1046 if hasattr(output, 'write'):
1047 output.write(text)
1048 return text
1049
1051 """ import a validity rule file """
1052
1053
1054 try:
1055 tree = ET.parse(inputpath)
1056 except IOError:
1057 if '\n' in inputpath:
1058
1059 tree = ET.fromstring(inputpath)
1060 else:
1061 raise
1062
1063
1064 element = tree.find('zero')
1065 if element is not None:
1066 for line in element.text.split('\n'):
1067 line = line.split('#',1)[0]
1068 if not line:
1069 continue
1070 lhacode = line.split()
1071 blockname = lhacode.pop(0)
1072 lhacode = [int(code) for code in lhacode ]
1073 self.add_zero(blockname, lhacode, '')
1074
1075
1076 element = tree.find('one')
1077 if element is not None:
1078 for line in element.text.split('\n'):
1079 line = line.split('#',1)[0]
1080 if not line:
1081 continue
1082 lhacode = line.split()
1083 blockname = lhacode.pop(0)
1084 lhacode = [int(code) for code in lhacode ]
1085 self.add_one(blockname, lhacode, '')
1086
1087
1088 element = tree.find('identical')
1089 if element is not None:
1090 for line in element.text.split('\n'):
1091 line = line.split('#',1)[0]
1092 if not line:
1093 continue
1094 line, lhacode2 = line.split(':')
1095 lhacode = line.split()
1096 blockname = lhacode.pop(0)
1097 lhacode = [int(code) for code in lhacode ]
1098 lhacode2 = [int(code) for code in lhacode2.split() ]
1099 self.add_identical(blockname, lhacode, lhacode2, '')
1100
1101
1102 element = tree.find('opposite')
1103 if element is not None:
1104 for line in element.text.split('\n'):
1105 line = line.split('#',1)[0]
1106 if not line:
1107 continue
1108 line, lhacode2 = line.split(':')
1109 lhacode = line.split()
1110 blockname = lhacode.pop(0)
1111 lhacode = [int(code) for code in lhacode ]
1112 lhacode2 = [int(code) for code in lhacode2.split() ]
1113 self.add_opposite(blockname, lhacode, lhacode2, '')
1114
1115
1116 element = tree.find('rule')
1117 if element is not None:
1118 for line in element.text.split('\n'):
1119 line = line.split('#',1)[0]
1120 if not line:
1121 continue
1122 line, rule = line.split(':')
1123 lhacode = line.split()
1124 blockname = lhacode.pop(0)
1125 self.add_rule(blockname, lhacode, rule, '')
1126
1127 @staticmethod
1129 """ read a param_card and return a dictionary with the associated value."""
1130
1131 output = ParamCard(path)
1132
1133
1134
1135 return output
1136
1137 @staticmethod
1139 """ read a param_card and return a dictionary with the associated value."""
1140
1141 output = {}
1142
1143 if isinstance(path, str):
1144 output = open(path, 'w')
1145 else:
1146 output = path
1147
1148 data.write(path)
1149
1150
1151 - def check_param_card(self, path, modify=False, write_missing=False, log=False):
1152 """Check that the restriction card are applied"""
1153
1154 is_modified = False
1155
1156 if isinstance(path,str):
1157 card = self.read_param_card(path)
1158 else:
1159 card = path
1160
1161
1162 for block, id, comment in self.zero:
1163 try:
1164 value = float(card[block].get(id).value)
1165 except KeyError:
1166 if modify and write_missing:
1167 new_param = Parameter(block=block,lhacode=id, value=0,
1168 comment='fixed by the model')
1169 if block in card:
1170 card[block].append(new_param)
1171 else:
1172 new_block = Block(block)
1173 card.append(new_block)
1174 new_block.append(new_param)
1175 else:
1176 if value != 0:
1177 if not modify:
1178 raise InvalidParamCard, 'parameter %s: %s is not at zero' % \
1179 (block, ' '.join([str(i) for i in id]))
1180 else:
1181 param = card[block].get(id)
1182 param.value = 0.0
1183 param.comment += ' fixed by the model'
1184 is_modified = True
1185 if log ==20:
1186 logger.log(log,'For model consistency, update %s with id %s to value %s',
1187 block, id, 0.0, '$MG:color:BLACK')
1188 elif log:
1189 logger.log(log,'For model consistency, update %s with id %s to value %s',
1190 block, id, 0.0)
1191
1192
1193 for block, id, comment in self.one:
1194 try:
1195 value = card[block].get(id).value
1196 except KeyError:
1197 if modify and write_missing:
1198 new_param = Parameter(block=block,lhacode=id, value=1,
1199 comment='fixed by the model')
1200 if block in card:
1201 card[block].append(new_param)
1202 else:
1203 new_block = Block(block)
1204 card.append(new_block)
1205 new_block.append(new_param)
1206 else:
1207 if value != 1:
1208 if not modify:
1209 raise InvalidParamCard, 'parameter %s: %s is not at one but at %s' % \
1210 (block, ' '.join([str(i) for i in id]), value)
1211 else:
1212 param = card[block].get(id)
1213 param.value = 1.0
1214 param.comment += ' fixed by the model'
1215 is_modified = True
1216 if log ==20:
1217 logger.log(log,'For model consistency, update %s with id %s to value %s',
1218 (block, id, 1.0), '$MG:color:BLACK')
1219 elif log:
1220 logger.log(log,'For model consistency, update %s with id %s to value %s',
1221 (block, id, 1.0))
1222
1223
1224
1225 for block, id1, id2, comment in self.identical:
1226 if block not in card:
1227 is_modified = True
1228 logger.warning('''Param card is not complete: Block %s is simply missing.
1229 We will use model default for all missing value! Please cross-check that
1230 this correspond to your expectation.''' % block)
1231 continue
1232 value2 = float(card[block].get(id2).value)
1233 try:
1234 param = card[block].get(id1)
1235 except KeyError:
1236 if modify and write_missing:
1237 new_param = Parameter(block=block,lhacode=id1, value=value2,
1238 comment='must be identical to %s' %id2)
1239 card[block].append(new_param)
1240 else:
1241 value1 = float(param.value)
1242
1243 if value1 != value2:
1244 if not modify:
1245 raise InvalidParamCard, 'parameter %s: %s is not to identical to parameter %s' % \
1246 (block, ' '.join([str(i) for i in id1]),
1247 ' '.join([str(i) for i in id2]))
1248 else:
1249 param = card[block].get(id1)
1250 param.value = value2
1251 param.comment += ' must be identical to %s' % id2
1252 is_modified = True
1253 if log ==20:
1254 logger.log(log,'For model consistency, update %s with id %s to value %s since it should be equal to parameter with id %s',
1255 block, id1, value2, id2, '$MG:color:BLACK')
1256 elif log:
1257 logger.log(log,'For model consistency, update %s with id %s to value %s since it should be equal to parameter with id %s',
1258 block, id1, value2, id2)
1259
1260 for block, id1, id2, comment in self.opposite:
1261 value2 = float(card[block].get(id2).value)
1262 try:
1263 param = card[block].get(id1)
1264 except KeyError:
1265 if modify and write_missing:
1266 new_param = Parameter(block=block,lhacode=id1, value=-value2,
1267 comment='must be opposite to to %s' %id2)
1268 card[block].append(new_param)
1269 else:
1270 value1 = float(param.value)
1271
1272 if value1 != -value2:
1273 if not modify:
1274 raise InvalidParamCard, 'parameter %s: %s is not to opposite to parameter %s' % \
1275 (block, ' '.join([str(i) for i in id1]),
1276 ' '.join([str(i) for i in id2]))
1277 else:
1278 param = card[block].get(id1)
1279 param.value = -value2
1280 param.comment += ' must be opposite to %s' % id2
1281 is_modified = True
1282 if log ==20:
1283 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',
1284 block, id1, -value2, id2, '$MG:color:BLACK')
1285 elif log:
1286 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',
1287 block, id1, -value2, id2)
1288
1289 return card, is_modified
1290
1293 """ """
1294
1295 if not outputpath:
1296 outputpath = path
1297 card = ParamCard(path)
1298 if not 'usqmix' in card:
1299
1300 card.write(outputpath)
1301 return
1302
1303
1304
1305 card.copy_param('mass', [6], 'sminputs', [6])
1306 card.copy_param('mass', [15], 'sminputs', [7])
1307 card.copy_param('mass', [23], 'sminputs', [4])
1308
1309
1310
1311 card.add_param('modsel',[1], value=1)
1312 card['modsel'].get([1]).format = 'int'
1313
1314
1315 scale = card['hmix'].scale
1316 if not scale:
1317 scale = 1
1318
1319
1320 if not card.has_param('sminputs', [2]):
1321 aem1 = card['sminputs'].get([1]).value
1322 mz = card['mass'].get([23]).value
1323 mw = card['mass'].get([24]).value
1324 gf = math.pi / math.sqrt(2) / aem1 * mz**2/ mw**2 /(mz**2-mw**2)
1325 card.add_param('sminputs', [2], gf, 'G_F [GeV^-2]')
1326
1327
1328 card.check_and_remove('usqmix', [1,1], 1.0)
1329 card.check_and_remove('usqmix', [2,2], 1.0)
1330 card.check_and_remove('usqmix', [4,4], 1.0)
1331 card.check_and_remove('usqmix', [5,5], 1.0)
1332 card.mod_param('usqmix', [3,3], 'stopmix', [1,1])
1333 card.mod_param('usqmix', [3,6], 'stopmix', [1,2])
1334 card.mod_param('usqmix', [6,3], 'stopmix', [2,1])
1335 card.mod_param('usqmix', [6,6], 'stopmix', [2,2])
1336
1337
1338 card.check_and_remove('dsqmix', [1,1], 1.0)
1339 card.check_and_remove('dsqmix', [2,2], 1.0)
1340 card.check_and_remove('dsqmix', [4,4], 1.0)
1341 card.check_and_remove('dsqmix', [5,5], 1.0)
1342 card.mod_param('dsqmix', [3,3], 'sbotmix', [1,1])
1343 card.mod_param('dsqmix', [3,6], 'sbotmix', [1,2])
1344 card.mod_param('dsqmix', [6,3], 'sbotmix', [2,1])
1345 card.mod_param('dsqmix', [6,6], 'sbotmix', [2,2])
1346
1347
1348
1349 card.check_and_remove('selmix', [1,1], 1.0)
1350 card.check_and_remove('selmix', [2,2], 1.0)
1351 card.check_and_remove('selmix', [4,4], 1.0)
1352 card.check_and_remove('selmix', [5,5], 1.0)
1353 card.mod_param('selmix', [3,3], 'staumix', [1,1])
1354 card.mod_param('selmix', [3,6], 'staumix', [1,2])
1355 card.mod_param('selmix', [6,3], 'staumix', [2,1])
1356 card.mod_param('selmix', [6,6], 'staumix', [2,2])
1357
1358
1359 card.mod_param('fralpha', [1], 'alpha', [' '])
1360
1361
1362 if not card.has_param('hmix', [3]):
1363 aem1 = card['sminputs'].get([1]).value
1364 tanb = card['hmix'].get([2]).value
1365 mz = card['mass'].get([23]).value
1366 mw = card['mass'].get([24]).value
1367 sw = math.sqrt(mz**2 - mw**2)/mz
1368 ee = 2 * math.sqrt(1/aem1) * math.sqrt(math.pi)
1369 vu = 2 * mw *sw /ee * math.sin(math.atan(tanb))
1370 card.add_param('hmix', [3], vu, 'higgs vev(Q) MSSM DRb')
1371 card['hmix'].scale= scale
1372
1373
1374 card.check_and_remove('vckm', [1,1], 1.0)
1375 card.check_and_remove('vckm', [2,2], 1.0)
1376 card.check_and_remove('vckm', [3,3], 1.0)
1377
1378
1379 card.check_and_remove('snumix', [1,1], 1.0)
1380 card.check_and_remove('snumix', [2,2], 1.0)
1381 card.check_and_remove('snumix', [3,3], 1.0)
1382
1383
1384 card.check_and_remove('upmns', [1,1], 1.0)
1385 card.check_and_remove('upmns', [2,2], 1.0)
1386 card.check_and_remove('upmns', [3,3], 1.0)
1387
1388
1389 ye = card['ye'].get([3, 3]).value
1390 te = card['te'].get([3, 3]).value
1391 card.mod_param('te', [3,3], 'ae', [3,3], value= te/ye, comment='A_tau(Q) DRbar')
1392 card.add_param('ae', [1,1], 0, 'A_e(Q) DRbar')
1393 card.add_param('ae', [2,2], 0, 'A_mu(Q) DRbar')
1394 card['ae'].scale = scale
1395 card['ye'].scale = scale
1396
1397
1398 yu = card['yu'].get([3, 3]).value
1399 tu = card['tu'].get([3, 3]).value
1400 card.mod_param('tu', [3,3], 'au', [3,3], value= tu/yu, comment='A_t(Q) DRbar')
1401 card.add_param('au', [1,1], 0, 'A_u(Q) DRbar')
1402 card.add_param('au', [2,2], 0, 'A_c(Q) DRbar')
1403 card['au'].scale = scale
1404 card['yu'].scale = scale
1405
1406
1407 yd = card['yd'].get([3, 3]).value
1408 td = card['td'].get([3, 3]).value
1409 if td:
1410 card.mod_param('td', [3,3], 'ad', [3,3], value= td/yd, comment='A_b(Q) DRbar')
1411 else:
1412 card.mod_param('td', [3,3], 'ad', [3,3], value= 0., comment='A_b(Q) DRbar')
1413 card.add_param('ad', [1,1], 0, 'A_d(Q) DRbar')
1414 card.add_param('ad', [2,2], 0, 'A_s(Q) DRbar')
1415 card['ad'].scale = scale
1416 card['yd'].scale = scale
1417
1418
1419 value = card['msl2'].get([1, 1]).value
1420 card.mod_param('msl2', [1,1], 'msoft', [31], math.sqrt(value))
1421 value = card['msl2'].get([2, 2]).value
1422 card.mod_param('msl2', [2,2], 'msoft', [32], math.sqrt(value))
1423 value = card['msl2'].get([3, 3]).value
1424 card.mod_param('msl2', [3,3], 'msoft', [33], math.sqrt(value))
1425 card['msoft'].scale = scale
1426
1427
1428 value = card['mse2'].get([1, 1]).value
1429 card.mod_param('mse2', [1,1], 'msoft', [34], math.sqrt(value))
1430 value = card['mse2'].get([2, 2]).value
1431 card.mod_param('mse2', [2,2], 'msoft', [35], math.sqrt(value))
1432 value = card['mse2'].get([3, 3]).value
1433 card.mod_param('mse2', [3,3], 'msoft', [36], math.sqrt(value))
1434
1435
1436 value = card['msq2'].get([1, 1]).value
1437 card.mod_param('msq2', [1,1], 'msoft', [41], math.sqrt(value))
1438 value = card['msq2'].get([2, 2]).value
1439 card.mod_param('msq2', [2,2], 'msoft', [42], math.sqrt(value))
1440 value = card['msq2'].get([3, 3]).value
1441 card.mod_param('msq2', [3,3], 'msoft', [43], math.sqrt(value))
1442
1443
1444 value = card['msu2'].get([1, 1]).value
1445 card.mod_param('msu2', [1,1], 'msoft', [44], math.sqrt(value))
1446 value = card['msu2'].get([2, 2]).value
1447 card.mod_param('msu2', [2,2], 'msoft', [45], math.sqrt(value))
1448 value = card['msu2'].get([3, 3]).value
1449 card.mod_param('msu2', [3,3], 'msoft', [46], math.sqrt(value))
1450
1451
1452 value = card['msd2'].get([1, 1]).value
1453 card.mod_param('msd2', [1,1], 'msoft', [47], math.sqrt(value))
1454 value = card['msd2'].get([2, 2]).value
1455 card.mod_param('msd2', [2,2], 'msoft', [48], math.sqrt(value))
1456 value = card['msd2'].get([3, 3]).value
1457 card.mod_param('msd2', [3,3], 'msoft', [49], math.sqrt(value))
1458
1459
1460
1461
1462
1463
1464 card.write(outputpath)
1465
1469 """
1470 """
1471
1472 if not outputpath:
1473 outputpath = path
1474 card = ParamCard(path)
1475 if 'usqmix' in card:
1476
1477 if outputpath != path and writting:
1478 card.write(outputpath)
1479 return card
1480
1481
1482
1483 card.remove_param('sminputs', [2])
1484 card.remove_param('sminputs', [4])
1485 card.remove_param('sminputs', [6])
1486 card.remove_param('sminputs', [7])
1487
1488
1489
1490 card.remove_param('modsel',[1])
1491
1492
1493
1494 card.add_param('usqmix', [1,1], 1.0)
1495 card.add_param('usqmix', [2,2], 1.0)
1496 card.add_param('usqmix', [4,4], 1.0)
1497 card.add_param('usqmix', [5,5], 1.0)
1498 card.mod_param('stopmix', [1,1], 'usqmix', [3,3])
1499 card.mod_param('stopmix', [1,2], 'usqmix', [3,6])
1500 card.mod_param('stopmix', [2,1], 'usqmix', [6,3])
1501 card.mod_param('stopmix', [2,2], 'usqmix', [6,6])
1502
1503
1504 card.add_param('dsqmix', [1,1], 1.0)
1505 card.add_param('dsqmix', [2,2], 1.0)
1506 card.add_param('dsqmix', [4,4], 1.0)
1507 card.add_param('dsqmix', [5,5], 1.0)
1508 card.mod_param('sbotmix', [1,1], 'dsqmix', [3,3])
1509 card.mod_param('sbotmix', [1,2], 'dsqmix', [3,6])
1510 card.mod_param('sbotmix', [2,1], 'dsqmix', [6,3])
1511 card.mod_param('sbotmix', [2,2], 'dsqmix', [6,6])
1512
1513
1514
1515 card.add_param('selmix', [1,1], 1.0)
1516 card.add_param('selmix', [2,2], 1.0)
1517 card.add_param('selmix', [4,4], 1.0)
1518 card.add_param('selmix', [5,5], 1.0)
1519 card.mod_param('staumix', [1,1], 'selmix', [3,3])
1520 card.mod_param('staumix', [1,2], 'selmix', [3,6])
1521 card.mod_param('staumix', [2,1], 'selmix', [6,3])
1522 card.mod_param('staumix', [2,2], 'selmix', [6,6])
1523
1524
1525 card.mod_param('alpha', [], 'fralpha', [1])
1526
1527
1528 card.remove_param('hmix', [3])
1529
1530
1531 card.add_param('vckm', [1,1], 1.0)
1532 card.add_param('vckm', [2,2], 1.0)
1533 card.add_param('vckm', [3,3], 1.0)
1534
1535
1536 card.add_param('snumix', [1,1], 1.0)
1537 card.add_param('snumix', [2,2], 1.0)
1538 card.add_param('snumix', [3,3], 1.0)
1539
1540
1541 card.add_param('upmns', [1,1], 1.0)
1542 card.add_param('upmns', [2,2], 1.0)
1543 card.add_param('upmns', [3,3], 1.0)
1544
1545
1546 ye = card['ye'].get([1, 1], default=0).value
1547 ae = card['ae'].get([1, 1], default=0).value
1548 card.mod_param('ae', [1,1], 'te', [1,1], value= ae * ye, comment='T_e(Q) DRbar')
1549 if ae * ye:
1550 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model
1551 Parameter ae [1, 1] times ye [1,1] should be 0'''
1552 card.remove_param('ae', [1,1])
1553
1554 ye = card['ye'].get([2, 2], default=0).value
1555
1556 ae = card['ae'].get([2, 2], default=0).value
1557 card.mod_param('ae', [2,2], 'te', [2,2], value= ae * ye, comment='T_mu(Q) DRbar')
1558 if ae * ye:
1559 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model
1560 Parameter ae [2, 2] times ye [2,2] should be 0'''
1561 card.remove_param('ae', [2,2])
1562
1563 ye = card['ye'].get([3, 3], default=0).value
1564 ae = card['ae'].get([3, 3], default=0).value
1565 card.mod_param('ae', [3,3], 'te', [3,3], value= ae * ye, comment='T_tau(Q) DRbar')
1566
1567
1568 yu = card['yu'].get([1, 1], default=0).value
1569 au = card['au'].get([1, 1], default=0).value
1570 card.mod_param('au', [1,1], 'tu', [1,1], value= au * yu, comment='T_u(Q) DRbar')
1571 if au * yu:
1572 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model
1573 Parameter au [1, 1] times yu [1,1] should be 0'''
1574 card.remove_param('au', [1,1])
1575
1576 ye = card['yu'].get([2, 2], default=0).value
1577
1578 ae = card['au'].get([2, 2], default=0).value
1579 card.mod_param('au', [2,2], 'tu', [2,2], value= au * yu, comment='T_c(Q) DRbar')
1580 if au * yu:
1581 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model
1582 Parameter au [2, 2] times yu [2,2] should be 0'''
1583 card.remove_param('au', [2,2])
1584
1585 yu = card['yu'].get([3, 3]).value
1586 au = card['au'].get([3, 3]).value
1587 card.mod_param('au', [3,3], 'tu', [3,3], value= au * yu, comment='T_t(Q) DRbar')
1588
1589
1590 yd = card['yd'].get([1, 1], default=0).value
1591 ad = card['ad'].get([1, 1], default=0).value
1592 card.mod_param('ad', [1,1], 'td', [1,1], value= ad * yd, comment='T_d(Q) DRbar')
1593 if ad * yd:
1594 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model
1595 Parameter ad [1, 1] times yd [1,1] should be 0'''
1596 card.remove_param('ad', [1,1])
1597
1598 ye = card['yd'].get([2, 2], default=0).value
1599
1600 ae = card['ad'].get([2, 2], default=0).value
1601 card.mod_param('ad', [2,2], 'td', [2,2], value= ad * yd, comment='T_s(Q) DRbar')
1602 if ad * yd:
1603 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model
1604 Parameter ad [2, 2] times yd [2,2] should be 0'''
1605 card.remove_param('ad', [2,2])
1606
1607 yd = card['yd'].get([3, 3]).value
1608 ad = card['ad'].get([3, 3]).value
1609 card.mod_param('ad', [3,3], 'td', [3,3], value= ad * yd, comment='T_b(Q) DRbar')
1610
1611
1612
1613 value = card['msoft'].get([31]).value
1614 card.mod_param('msoft', [31], 'msl2', [1,1], value**2)
1615 value = card['msoft'].get([32]).value
1616 card.mod_param('msoft', [32], 'msl2', [2,2], value**2)
1617 value = card['msoft'].get([33]).value
1618 card.mod_param('msoft', [33], 'msl2', [3,3], value**2)
1619
1620
1621 value = card['msoft'].get([34]).value
1622 card.mod_param('msoft', [34], 'mse2', [1,1], value**2)
1623 value = card['msoft'].get([35]).value
1624 card.mod_param('msoft', [35], 'mse2', [2,2], value**2)
1625 value = card['msoft'].get([36]).value
1626 card.mod_param('msoft', [36], 'mse2', [3,3], value**2)
1627
1628
1629 value = card['msoft'].get([41]).value
1630 card.mod_param('msoft', [41], 'msq2', [1,1], value**2)
1631 value = card['msoft'].get([42]).value
1632 card.mod_param('msoft', [42], 'msq2', [2,2], value**2)
1633 value = card['msoft'].get([43]).value
1634 card.mod_param('msoft', [43], 'msq2', [3,3], value**2)
1635
1636
1637 value = card['msoft'].get([44]).value
1638 card.mod_param('msoft', [44], 'msu2', [1,1], value**2)
1639 value = card['msoft'].get([45]).value
1640 card.mod_param('msoft', [45], 'msu2', [2,2], value**2)
1641 value = card['msoft'].get([46]).value
1642 card.mod_param('msoft', [46], 'msu2', [3,3], value**2)
1643
1644
1645 value = card['msoft'].get([47]).value
1646 card.mod_param('msoft', [47], 'msd2', [1,1], value**2)
1647 value = card['msoft'].get([48]).value
1648 card.mod_param('msoft', [48], 'msd2', [2,2], value**2)
1649 value = card['msoft'].get([49]).value
1650 card.mod_param('msoft', [49], 'msd2', [3,3], value**2)
1651
1652
1653
1654
1655 if writting:
1656 card.write(outputpath)
1657 return card
1658
1661 """ modify the current param_card such that it agrees with the restriction"""
1662
1663 if not outputpath:
1664 outputpath = path
1665
1666 cardrule = ParamCardRule()
1667 cardrule.load_rule(restrictpath)
1668 try :
1669 cardrule.check_param_card(path, modify=False)
1670 except InvalidParamCard:
1671 new_data, was_modified = cardrule.check_param_card(path, modify=True, write_missing=True)
1672 if was_modified:
1673 cardrule.write_param_card(outputpath, new_data)
1674 else:
1675 if path != outputpath:
1676 shutil.copy(path, outputpath)
1677 return cardrule
1678
1680 """ check if the current param_card agrees with the restriction"""
1681
1682 if restrictpath is None:
1683 restrictpath = os.path.dirname(path)
1684 restrictpath = os.path.join(restrictpath, os.pardir, os.pardir, 'Source',
1685 'MODEL', 'param_card_rule.dat')
1686 if not os.path.exists(restrictpath):
1687 restrictpath = os.path.dirname(path)
1688 restrictpath = os.path.join(restrictpath, os.pardir, 'Source',
1689 'MODEL', 'param_card_rule.dat')
1690 if not os.path.exists(restrictpath):
1691 return True
1692
1693 cardrule = ParamCardRule()
1694 cardrule.load_rule(restrictpath)
1695 cardrule.check_param_card(path, modify=False)
1696
1697
1698
1699 if '__main__' == __name__:
1700
1701
1702
1703
1704 import sys
1705 args = sys.argv
1706 sys.path.append(os.path.dirname(__file__))
1707 convert_to_slha1(args[1] , args[2])
1708