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, error=None):
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 if error is None:
911 self.cross.append({'bench' : self.itertag, 'run_name': run_name, 'cross(pb)':cross})
912 else:
913 self.cross.append({'bench' : self.itertag, 'run_name': run_name, 'cross(pb)':cross, 'error(pb)':error})
914
915 - def write_summary(self, path, order=None, lastline=False, nbcol=20):
916 """ """
917
918 if path:
919 ff = open(path, 'w')
920 else:
921 ff = StringIO.StringIO()
922 if order:
923 keys = order
924 else:
925 keys = self.cross[0].keys()
926 keys.remove('bench')
927 keys.remove('run_name')
928 keys.sort()
929
930 formatting = "#%s%s%s\n" %('%%-%is ' % (nbcol-1), ('%%-%is ' % (nbcol))* len(self.param_order),
931 ('%%-%is ' % (nbcol))* len(keys))
932
933 if not lastline:
934 ff.write(formatting % tuple(['run_name'] + self.param_order + keys))
935 formatting = "%s%s%s\n" %('%%-%is ' % (nbcol), ('%%-%ie ' % (nbcol))* len(self.param_order),
936 ('%%-%ie ' % (nbcol))* len(keys))
937
938 if not lastline:
939 to_print = self.cross
940 else:
941 to_print = self.cross[-1:]
942 for info in to_print:
943 name = info['run_name']
944 bench = info['bench']
945 data = []
946 for k in keys:
947 data.append(info[k])
948
949 ff.write(formatting % tuple([name] + bench + data))
950
951 if not path:
952 return ff.getvalue()
953
954
956 """returns a smart name for the next run"""
957
958 if '_' in run_name:
959 name, value = run_name.rsplit('_',1)
960 if value.isdigit():
961 return '%s_%02i' % (name, float(value)+1)
962
963 return '%s_scan_02' % run_name
964
967 """ A class for storing the linked between the different parameter of
968 the param_card.
969 Able to write a file 'param_card_rule.dat'
970 Able to read a file 'param_card_rule.dat'
971 Able to check the validity of a param_card.dat
972 """
973
974
976 """initialize an object """
977
978
979 self.zero = []
980 self.one = []
981 self.identical = []
982 self.opposite = []
983
984
985 self.rule = []
986
987 if inputpath:
988 self.load_rule(inputpath)
989
990 - def add_zero(self, lhablock, lhacode, comment=''):
991 """add a zero rule"""
992 self.zero.append( (lhablock, lhacode, comment) )
993
994 - def add_one(self, lhablock, lhacode, comment=''):
995 """add a one rule"""
996 self.one.append( (lhablock, lhacode, comment) )
997
998 - def add_identical(self, lhablock, lhacode, lhacode2, comment=''):
999 """add a rule for identical value"""
1000 self.identical.append( (lhablock, lhacode, lhacode2, comment) )
1001
1002 - def add_opposite(self, lhablock, lhacode, lhacode2, comment=''):
1003 """add a rule for identical value"""
1004 self.opposite.append( (lhablock, lhacode, lhacode2, comment) )
1005
1006
1007 - def add_rule(self, lhablock, lhacode, rule, comment=''):
1008 """add a rule for constraint value"""
1009 self.rule.append( (lhablock, lhacode, rule) )
1010
1012
1013 text = """<file>######################################################################
1014 ## VALIDITY RULE FOR THE PARAM_CARD ####
1015 ######################################################################\n"""
1016
1017
1018 text +='<zero>\n'
1019 for name, id, comment in self.zero:
1020 text+=' %s %s # %s\n' % (name, ' '.join([str(i) for i in id]),
1021 comment)
1022
1023 text +='</zero>\n<one>\n'
1024 for name, id, comment in self.one:
1025 text+=' %s %s # %s\n' % (name, ' '.join([str(i) for i in id]),
1026 comment)
1027
1028 text +='</one>\n<identical>\n'
1029 for name, id,id2, comment in self.identical:
1030 text+=' %s %s : %s # %s\n' % (name, ' '.join([str(i) for i in id]),
1031 ' '.join([str(i) for i in id2]), comment)
1032
1033
1034 text +='</identical>\n<opposite>\n'
1035 for name, id,id2, comment in self.opposite:
1036 text+=' %s %s : %s # %s\n' % (name, ' '.join([str(i) for i in id]),
1037 ' '.join([str(i) for i in id2]), comment)
1038
1039
1040 text += '</opposite>\n<constraint>\n'
1041 for name, id, rule, comment in self.rule:
1042 text += ' %s %s : %s # %s\n' % (name, ' '.join([str(i) for i in id]),
1043 rule, comment)
1044 text += '</constraint>\n</file>'
1045
1046 if isinstance(output, str):
1047 output = open(output,'w')
1048 if hasattr(output, 'write'):
1049 output.write(text)
1050 return text
1051
1053 """ import a validity rule file """
1054
1055
1056 try:
1057 tree = ET.parse(inputpath)
1058 except IOError:
1059 if '\n' in inputpath:
1060
1061 tree = ET.fromstring(inputpath)
1062 else:
1063 raise
1064
1065
1066 element = tree.find('zero')
1067 if element is not None:
1068 for line in element.text.split('\n'):
1069 line = line.split('#',1)[0]
1070 if not line:
1071 continue
1072 lhacode = line.split()
1073 blockname = lhacode.pop(0)
1074 lhacode = [int(code) for code in lhacode ]
1075 self.add_zero(blockname, lhacode, '')
1076
1077
1078 element = tree.find('one')
1079 if element is not None:
1080 for line in element.text.split('\n'):
1081 line = line.split('#',1)[0]
1082 if not line:
1083 continue
1084 lhacode = line.split()
1085 blockname = lhacode.pop(0)
1086 lhacode = [int(code) for code in lhacode ]
1087 self.add_one(blockname, lhacode, '')
1088
1089
1090 element = tree.find('identical')
1091 if element is not None:
1092 for line in element.text.split('\n'):
1093 line = line.split('#',1)[0]
1094 if not line:
1095 continue
1096 line, lhacode2 = line.split(':')
1097 lhacode = line.split()
1098 blockname = lhacode.pop(0)
1099 lhacode = [int(code) for code in lhacode ]
1100 lhacode2 = [int(code) for code in lhacode2.split() ]
1101 self.add_identical(blockname, lhacode, lhacode2, '')
1102
1103
1104 element = tree.find('opposite')
1105 if element is not None:
1106 for line in element.text.split('\n'):
1107 line = line.split('#',1)[0]
1108 if not line:
1109 continue
1110 line, lhacode2 = line.split(':')
1111 lhacode = line.split()
1112 blockname = lhacode.pop(0)
1113 lhacode = [int(code) for code in lhacode ]
1114 lhacode2 = [int(code) for code in lhacode2.split() ]
1115 self.add_opposite(blockname, lhacode, lhacode2, '')
1116
1117
1118 element = tree.find('rule')
1119 if element is not None:
1120 for line in element.text.split('\n'):
1121 line = line.split('#',1)[0]
1122 if not line:
1123 continue
1124 line, rule = line.split(':')
1125 lhacode = line.split()
1126 blockname = lhacode.pop(0)
1127 self.add_rule(blockname, lhacode, rule, '')
1128
1129 @staticmethod
1131 """ read a param_card and return a dictionary with the associated value."""
1132
1133 output = ParamCard(path)
1134
1135
1136
1137 return output
1138
1139 @staticmethod
1141 """ read a param_card and return a dictionary with the associated value."""
1142
1143 output = {}
1144
1145 if isinstance(path, str):
1146 output = open(path, 'w')
1147 else:
1148 output = path
1149
1150 data.write(path)
1151
1152
1153 - def check_param_card(self, path, modify=False, write_missing=False, log=False):
1154 """Check that the restriction card are applied"""
1155
1156 is_modified = False
1157
1158 if isinstance(path,str):
1159 card = self.read_param_card(path)
1160 else:
1161 card = path
1162
1163
1164 for block, id, comment in self.zero:
1165 try:
1166 value = float(card[block].get(id).value)
1167 except KeyError:
1168 if modify and write_missing:
1169 new_param = Parameter(block=block,lhacode=id, value=0,
1170 comment='fixed by the model')
1171 if block in card:
1172 card[block].append(new_param)
1173 else:
1174 new_block = Block(block)
1175 card.append(new_block)
1176 new_block.append(new_param)
1177 else:
1178 if value != 0:
1179 if not modify:
1180 raise InvalidParamCard, 'parameter %s: %s is not at zero' % \
1181 (block, ' '.join([str(i) for i in id]))
1182 else:
1183 param = card[block].get(id)
1184 param.value = 0.0
1185 param.comment += ' fixed by the model'
1186 is_modified = True
1187 if log ==20:
1188 logger.log(log,'For model consistency, update %s with id %s to value %s',
1189 block, id, 0.0, '$MG:color:BLACK')
1190 elif log:
1191 logger.log(log,'For model consistency, update %s with id %s to value %s',
1192 block, id, 0.0)
1193
1194
1195 for block, id, comment in self.one:
1196 try:
1197 value = card[block].get(id).value
1198 except KeyError:
1199 if modify and write_missing:
1200 new_param = Parameter(block=block,lhacode=id, value=1,
1201 comment='fixed by the model')
1202 if block in card:
1203 card[block].append(new_param)
1204 else:
1205 new_block = Block(block)
1206 card.append(new_block)
1207 new_block.append(new_param)
1208 else:
1209 if value != 1:
1210 if not modify:
1211 raise InvalidParamCard, 'parameter %s: %s is not at one but at %s' % \
1212 (block, ' '.join([str(i) for i in id]), value)
1213 else:
1214 param = card[block].get(id)
1215 param.value = 1.0
1216 param.comment += ' fixed by the model'
1217 is_modified = True
1218 if log ==20:
1219 logger.log(log,'For model consistency, update %s with id %s to value %s',
1220 (block, id, 1.0), '$MG:color:BLACK')
1221 elif log:
1222 logger.log(log,'For model consistency, update %s with id %s to value %s',
1223 (block, id, 1.0))
1224
1225
1226
1227 for block, id1, id2, comment in self.identical:
1228 if block not in card:
1229 is_modified = True
1230 logger.warning('''Param card is not complete: Block %s is simply missing.
1231 We will use model default for all missing value! Please cross-check that
1232 this correspond to your expectation.''' % block)
1233 continue
1234 value2 = float(card[block].get(id2).value)
1235 try:
1236 param = card[block].get(id1)
1237 except KeyError:
1238 if modify and write_missing:
1239 new_param = Parameter(block=block,lhacode=id1, value=value2,
1240 comment='must be identical to %s' %id2)
1241 card[block].append(new_param)
1242 else:
1243 value1 = float(param.value)
1244
1245 if value1 != value2:
1246 if not modify:
1247 raise InvalidParamCard, 'parameter %s: %s is not to identical to parameter %s' % \
1248 (block, ' '.join([str(i) for i in id1]),
1249 ' '.join([str(i) for i in id2]))
1250 else:
1251 param = card[block].get(id1)
1252 param.value = value2
1253 param.comment += ' must be identical to %s' % id2
1254 is_modified = True
1255 if log ==20:
1256 logger.log(log,'For model consistency, update %s with id %s to value %s since it should be equal to parameter with id %s',
1257 block, id1, value2, id2, '$MG:color:BLACK')
1258 elif log:
1259 logger.log(log,'For model consistency, update %s with id %s to value %s since it should be equal to parameter with id %s',
1260 block, id1, value2, id2)
1261
1262 for block, id1, id2, comment in self.opposite:
1263 value2 = float(card[block].get(id2).value)
1264 try:
1265 param = card[block].get(id1)
1266 except KeyError:
1267 if modify and write_missing:
1268 new_param = Parameter(block=block,lhacode=id1, value=-value2,
1269 comment='must be opposite to to %s' %id2)
1270 card[block].append(new_param)
1271 else:
1272 value1 = float(param.value)
1273
1274 if value1 != -value2:
1275 if not modify:
1276 raise InvalidParamCard, 'parameter %s: %s is not to opposite to parameter %s' % \
1277 (block, ' '.join([str(i) for i in id1]),
1278 ' '.join([str(i) for i in id2]))
1279 else:
1280 param = card[block].get(id1)
1281 param.value = -value2
1282 param.comment += ' must be opposite to %s' % id2
1283 is_modified = True
1284 if log ==20:
1285 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',
1286 block, id1, -value2, id2, '$MG:color:BLACK')
1287 elif log:
1288 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',
1289 block, id1, -value2, id2)
1290
1291 return card, is_modified
1292
1295 """ """
1296
1297 if not outputpath:
1298 outputpath = path
1299 card = ParamCard(path)
1300 if not 'usqmix' in card:
1301
1302 card.write(outputpath)
1303 return
1304
1305
1306
1307 card.copy_param('mass', [6], 'sminputs', [6])
1308 card.copy_param('mass', [15], 'sminputs', [7])
1309 card.copy_param('mass', [23], 'sminputs', [4])
1310
1311
1312
1313 card.add_param('modsel',[1], value=1)
1314 card['modsel'].get([1]).format = 'int'
1315
1316
1317 scale = card['hmix'].scale
1318 if not scale:
1319 scale = 1
1320
1321
1322 if not card.has_param('sminputs', [2]):
1323 aem1 = card['sminputs'].get([1]).value
1324 mz = card['mass'].get([23]).value
1325 mw = card['mass'].get([24]).value
1326 gf = math.pi / math.sqrt(2) / aem1 * mz**2/ mw**2 /(mz**2-mw**2)
1327 card.add_param('sminputs', [2], gf, 'G_F [GeV^-2]')
1328
1329
1330 card.check_and_remove('usqmix', [1,1], 1.0)
1331 card.check_and_remove('usqmix', [2,2], 1.0)
1332 card.check_and_remove('usqmix', [4,4], 1.0)
1333 card.check_and_remove('usqmix', [5,5], 1.0)
1334 card.mod_param('usqmix', [3,3], 'stopmix', [1,1])
1335 card.mod_param('usqmix', [3,6], 'stopmix', [1,2])
1336 card.mod_param('usqmix', [6,3], 'stopmix', [2,1])
1337 card.mod_param('usqmix', [6,6], 'stopmix', [2,2])
1338
1339
1340 card.check_and_remove('dsqmix', [1,1], 1.0)
1341 card.check_and_remove('dsqmix', [2,2], 1.0)
1342 card.check_and_remove('dsqmix', [4,4], 1.0)
1343 card.check_and_remove('dsqmix', [5,5], 1.0)
1344 card.mod_param('dsqmix', [3,3], 'sbotmix', [1,1])
1345 card.mod_param('dsqmix', [3,6], 'sbotmix', [1,2])
1346 card.mod_param('dsqmix', [6,3], 'sbotmix', [2,1])
1347 card.mod_param('dsqmix', [6,6], 'sbotmix', [2,2])
1348
1349
1350
1351 card.check_and_remove('selmix', [1,1], 1.0)
1352 card.check_and_remove('selmix', [2,2], 1.0)
1353 card.check_and_remove('selmix', [4,4], 1.0)
1354 card.check_and_remove('selmix', [5,5], 1.0)
1355 card.mod_param('selmix', [3,3], 'staumix', [1,1])
1356 card.mod_param('selmix', [3,6], 'staumix', [1,2])
1357 card.mod_param('selmix', [6,3], 'staumix', [2,1])
1358 card.mod_param('selmix', [6,6], 'staumix', [2,2])
1359
1360
1361 card.mod_param('fralpha', [1], 'alpha', [' '])
1362
1363
1364 if not card.has_param('hmix', [3]):
1365 aem1 = card['sminputs'].get([1]).value
1366 tanb = card['hmix'].get([2]).value
1367 mz = card['mass'].get([23]).value
1368 mw = card['mass'].get([24]).value
1369 sw = math.sqrt(mz**2 - mw**2)/mz
1370 ee = 2 * math.sqrt(1/aem1) * math.sqrt(math.pi)
1371 vu = 2 * mw *sw /ee * math.sin(math.atan(tanb))
1372 card.add_param('hmix', [3], vu, 'higgs vev(Q) MSSM DRb')
1373 card['hmix'].scale= scale
1374
1375
1376 card.check_and_remove('vckm', [1,1], 1.0)
1377 card.check_and_remove('vckm', [2,2], 1.0)
1378 card.check_and_remove('vckm', [3,3], 1.0)
1379
1380
1381 card.check_and_remove('snumix', [1,1], 1.0)
1382 card.check_and_remove('snumix', [2,2], 1.0)
1383 card.check_and_remove('snumix', [3,3], 1.0)
1384
1385
1386 card.check_and_remove('upmns', [1,1], 1.0)
1387 card.check_and_remove('upmns', [2,2], 1.0)
1388 card.check_and_remove('upmns', [3,3], 1.0)
1389
1390
1391 ye = card['ye'].get([3, 3]).value
1392 te = card['te'].get([3, 3]).value
1393 card.mod_param('te', [3,3], 'ae', [3,3], value= te/ye, comment='A_tau(Q) DRbar')
1394 card.add_param('ae', [1,1], 0, 'A_e(Q) DRbar')
1395 card.add_param('ae', [2,2], 0, 'A_mu(Q) DRbar')
1396 card['ae'].scale = scale
1397 card['ye'].scale = scale
1398
1399
1400 yu = card['yu'].get([3, 3]).value
1401 tu = card['tu'].get([3, 3]).value
1402 card.mod_param('tu', [3,3], 'au', [3,3], value= tu/yu, comment='A_t(Q) DRbar')
1403 card.add_param('au', [1,1], 0, 'A_u(Q) DRbar')
1404 card.add_param('au', [2,2], 0, 'A_c(Q) DRbar')
1405 card['au'].scale = scale
1406 card['yu'].scale = scale
1407
1408
1409 yd = card['yd'].get([3, 3]).value
1410 td = card['td'].get([3, 3]).value
1411 if td:
1412 card.mod_param('td', [3,3], 'ad', [3,3], value= td/yd, comment='A_b(Q) DRbar')
1413 else:
1414 card.mod_param('td', [3,3], 'ad', [3,3], value= 0., comment='A_b(Q) DRbar')
1415 card.add_param('ad', [1,1], 0, 'A_d(Q) DRbar')
1416 card.add_param('ad', [2,2], 0, 'A_s(Q) DRbar')
1417 card['ad'].scale = scale
1418 card['yd'].scale = scale
1419
1420
1421 value = card['msl2'].get([1, 1]).value
1422 card.mod_param('msl2', [1,1], 'msoft', [31], math.sqrt(value))
1423 value = card['msl2'].get([2, 2]).value
1424 card.mod_param('msl2', [2,2], 'msoft', [32], math.sqrt(value))
1425 value = card['msl2'].get([3, 3]).value
1426 card.mod_param('msl2', [3,3], 'msoft', [33], math.sqrt(value))
1427 card['msoft'].scale = scale
1428
1429
1430 value = card['mse2'].get([1, 1]).value
1431 card.mod_param('mse2', [1,1], 'msoft', [34], math.sqrt(value))
1432 value = card['mse2'].get([2, 2]).value
1433 card.mod_param('mse2', [2,2], 'msoft', [35], math.sqrt(value))
1434 value = card['mse2'].get([3, 3]).value
1435 card.mod_param('mse2', [3,3], 'msoft', [36], math.sqrt(value))
1436
1437
1438 value = card['msq2'].get([1, 1]).value
1439 card.mod_param('msq2', [1,1], 'msoft', [41], math.sqrt(value))
1440 value = card['msq2'].get([2, 2]).value
1441 card.mod_param('msq2', [2,2], 'msoft', [42], math.sqrt(value))
1442 value = card['msq2'].get([3, 3]).value
1443 card.mod_param('msq2', [3,3], 'msoft', [43], math.sqrt(value))
1444
1445
1446 value = card['msu2'].get([1, 1]).value
1447 card.mod_param('msu2', [1,1], 'msoft', [44], math.sqrt(value))
1448 value = card['msu2'].get([2, 2]).value
1449 card.mod_param('msu2', [2,2], 'msoft', [45], math.sqrt(value))
1450 value = card['msu2'].get([3, 3]).value
1451 card.mod_param('msu2', [3,3], 'msoft', [46], math.sqrt(value))
1452
1453
1454 value = card['msd2'].get([1, 1]).value
1455 card.mod_param('msd2', [1,1], 'msoft', [47], math.sqrt(value))
1456 value = card['msd2'].get([2, 2]).value
1457 card.mod_param('msd2', [2,2], 'msoft', [48], math.sqrt(value))
1458 value = card['msd2'].get([3, 3]).value
1459 card.mod_param('msd2', [3,3], 'msoft', [49], math.sqrt(value))
1460
1461
1462
1463
1464
1465
1466 card.write(outputpath)
1467
1471 """
1472 """
1473
1474 if not outputpath:
1475 outputpath = path
1476 card = ParamCard(path)
1477 if 'usqmix' in card:
1478
1479 if outputpath != path and writting:
1480 card.write(outputpath)
1481 return card
1482
1483
1484
1485 card.remove_param('sminputs', [2])
1486 card.remove_param('sminputs', [4])
1487 card.remove_param('sminputs', [6])
1488 card.remove_param('sminputs', [7])
1489
1490
1491
1492 card.remove_param('modsel',[1])
1493
1494
1495
1496 card.add_param('usqmix', [1,1], 1.0)
1497 card.add_param('usqmix', [2,2], 1.0)
1498 card.add_param('usqmix', [4,4], 1.0)
1499 card.add_param('usqmix', [5,5], 1.0)
1500 card.mod_param('stopmix', [1,1], 'usqmix', [3,3])
1501 card.mod_param('stopmix', [1,2], 'usqmix', [3,6])
1502 card.mod_param('stopmix', [2,1], 'usqmix', [6,3])
1503 card.mod_param('stopmix', [2,2], 'usqmix', [6,6])
1504
1505
1506 card.add_param('dsqmix', [1,1], 1.0)
1507 card.add_param('dsqmix', [2,2], 1.0)
1508 card.add_param('dsqmix', [4,4], 1.0)
1509 card.add_param('dsqmix', [5,5], 1.0)
1510 card.mod_param('sbotmix', [1,1], 'dsqmix', [3,3])
1511 card.mod_param('sbotmix', [1,2], 'dsqmix', [3,6])
1512 card.mod_param('sbotmix', [2,1], 'dsqmix', [6,3])
1513 card.mod_param('sbotmix', [2,2], 'dsqmix', [6,6])
1514
1515
1516
1517 card.add_param('selmix', [1,1], 1.0)
1518 card.add_param('selmix', [2,2], 1.0)
1519 card.add_param('selmix', [4,4], 1.0)
1520 card.add_param('selmix', [5,5], 1.0)
1521 card.mod_param('staumix', [1,1], 'selmix', [3,3])
1522 card.mod_param('staumix', [1,2], 'selmix', [3,6])
1523 card.mod_param('staumix', [2,1], 'selmix', [6,3])
1524 card.mod_param('staumix', [2,2], 'selmix', [6,6])
1525
1526
1527 card.mod_param('alpha', [], 'fralpha', [1])
1528
1529
1530 card.remove_param('hmix', [3])
1531
1532
1533 card.add_param('vckm', [1,1], 1.0)
1534 card.add_param('vckm', [2,2], 1.0)
1535 card.add_param('vckm', [3,3], 1.0)
1536
1537
1538 card.add_param('snumix', [1,1], 1.0)
1539 card.add_param('snumix', [2,2], 1.0)
1540 card.add_param('snumix', [3,3], 1.0)
1541
1542
1543 card.add_param('upmns', [1,1], 1.0)
1544 card.add_param('upmns', [2,2], 1.0)
1545 card.add_param('upmns', [3,3], 1.0)
1546
1547
1548 ye = card['ye'].get([1, 1], default=0).value
1549 ae = card['ae'].get([1, 1], default=0).value
1550 card.mod_param('ae', [1,1], 'te', [1,1], value= ae * ye, comment='T_e(Q) DRbar')
1551 if ae * ye:
1552 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model
1553 Parameter ae [1, 1] times ye [1,1] should be 0'''
1554 card.remove_param('ae', [1,1])
1555
1556 ye = card['ye'].get([2, 2], default=0).value
1557
1558 ae = card['ae'].get([2, 2], default=0).value
1559 card.mod_param('ae', [2,2], 'te', [2,2], value= ae * ye, comment='T_mu(Q) DRbar')
1560 if ae * ye:
1561 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model
1562 Parameter ae [2, 2] times ye [2,2] should be 0'''
1563 card.remove_param('ae', [2,2])
1564
1565 ye = card['ye'].get([3, 3], default=0).value
1566 ae = card['ae'].get([3, 3], default=0).value
1567 card.mod_param('ae', [3,3], 'te', [3,3], value= ae * ye, comment='T_tau(Q) DRbar')
1568
1569
1570 yu = card['yu'].get([1, 1], default=0).value
1571 au = card['au'].get([1, 1], default=0).value
1572 card.mod_param('au', [1,1], 'tu', [1,1], value= au * yu, comment='T_u(Q) DRbar')
1573 if au * yu:
1574 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model
1575 Parameter au [1, 1] times yu [1,1] should be 0'''
1576 card.remove_param('au', [1,1])
1577
1578 ye = card['yu'].get([2, 2], default=0).value
1579
1580 ae = card['au'].get([2, 2], default=0).value
1581 card.mod_param('au', [2,2], 'tu', [2,2], value= au * yu, comment='T_c(Q) DRbar')
1582 if au * yu:
1583 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model
1584 Parameter au [2, 2] times yu [2,2] should be 0'''
1585 card.remove_param('au', [2,2])
1586
1587 yu = card['yu'].get([3, 3]).value
1588 au = card['au'].get([3, 3]).value
1589 card.mod_param('au', [3,3], 'tu', [3,3], value= au * yu, comment='T_t(Q) DRbar')
1590
1591
1592 yd = card['yd'].get([1, 1], default=0).value
1593 ad = card['ad'].get([1, 1], default=0).value
1594 card.mod_param('ad', [1,1], 'td', [1,1], value= ad * yd, comment='T_d(Q) DRbar')
1595 if ad * yd:
1596 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model
1597 Parameter ad [1, 1] times yd [1,1] should be 0'''
1598 card.remove_param('ad', [1,1])
1599
1600 ye = card['yd'].get([2, 2], default=0).value
1601
1602 ae = card['ad'].get([2, 2], default=0).value
1603 card.mod_param('ad', [2,2], 'td', [2,2], value= ad * yd, comment='T_s(Q) DRbar')
1604 if ad * yd:
1605 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model
1606 Parameter ad [2, 2] times yd [2,2] should be 0'''
1607 card.remove_param('ad', [2,2])
1608
1609 yd = card['yd'].get([3, 3]).value
1610 ad = card['ad'].get([3, 3]).value
1611 card.mod_param('ad', [3,3], 'td', [3,3], value= ad * yd, comment='T_b(Q) DRbar')
1612
1613
1614
1615 value = card['msoft'].get([31]).value
1616 card.mod_param('msoft', [31], 'msl2', [1,1], value**2)
1617 value = card['msoft'].get([32]).value
1618 card.mod_param('msoft', [32], 'msl2', [2,2], value**2)
1619 value = card['msoft'].get([33]).value
1620 card.mod_param('msoft', [33], 'msl2', [3,3], value**2)
1621
1622
1623 value = card['msoft'].get([34]).value
1624 card.mod_param('msoft', [34], 'mse2', [1,1], value**2)
1625 value = card['msoft'].get([35]).value
1626 card.mod_param('msoft', [35], 'mse2', [2,2], value**2)
1627 value = card['msoft'].get([36]).value
1628 card.mod_param('msoft', [36], 'mse2', [3,3], value**2)
1629
1630
1631 value = card['msoft'].get([41]).value
1632 card.mod_param('msoft', [41], 'msq2', [1,1], value**2)
1633 value = card['msoft'].get([42]).value
1634 card.mod_param('msoft', [42], 'msq2', [2,2], value**2)
1635 value = card['msoft'].get([43]).value
1636 card.mod_param('msoft', [43], 'msq2', [3,3], value**2)
1637
1638
1639 value = card['msoft'].get([44]).value
1640 card.mod_param('msoft', [44], 'msu2', [1,1], value**2)
1641 value = card['msoft'].get([45]).value
1642 card.mod_param('msoft', [45], 'msu2', [2,2], value**2)
1643 value = card['msoft'].get([46]).value
1644 card.mod_param('msoft', [46], 'msu2', [3,3], value**2)
1645
1646
1647 value = card['msoft'].get([47]).value
1648 card.mod_param('msoft', [47], 'msd2', [1,1], value**2)
1649 value = card['msoft'].get([48]).value
1650 card.mod_param('msoft', [48], 'msd2', [2,2], value**2)
1651 value = card['msoft'].get([49]).value
1652 card.mod_param('msoft', [49], 'msd2', [3,3], value**2)
1653
1654
1655
1656
1657 if writting:
1658 card.write(outputpath)
1659 return card
1660
1663 """ modify the current param_card such that it agrees with the restriction"""
1664
1665 if not outputpath:
1666 outputpath = path
1667
1668 cardrule = ParamCardRule()
1669 cardrule.load_rule(restrictpath)
1670 try :
1671 cardrule.check_param_card(path, modify=False)
1672 except InvalidParamCard:
1673 new_data, was_modified = cardrule.check_param_card(path, modify=True, write_missing=True)
1674 if was_modified:
1675 cardrule.write_param_card(outputpath, new_data)
1676 else:
1677 if path != outputpath:
1678 shutil.copy(path, outputpath)
1679 return cardrule
1680
1682 """ check if the current param_card agrees with the restriction"""
1683
1684 if restrictpath is None:
1685 restrictpath = os.path.dirname(path)
1686 restrictpath = os.path.join(restrictpath, os.pardir, os.pardir, 'Source',
1687 'MODEL', 'param_card_rule.dat')
1688 if not os.path.exists(restrictpath):
1689 restrictpath = os.path.dirname(path)
1690 restrictpath = os.path.join(restrictpath, os.pardir, 'Source',
1691 'MODEL', 'param_card_rule.dat')
1692 if not os.path.exists(restrictpath):
1693 return True
1694
1695 cardrule = ParamCardRule()
1696 cardrule.load_rule(restrictpath)
1697 cardrule.check_param_card(path, modify=False)
1698
1699
1700
1701 if '__main__' == __name__:
1702
1703
1704
1705
1706 import sys
1707 args = sys.argv
1708 sys.path.append(os.path.dirname(__file__))
1709 convert_to_slha1(args[1] , args[2])
1710