Package models :: Module check_param_card
[hide private]
[frames] | no frames]

Source Code for Module models.check_param_card

   1  from __future__ import division 
   2  import xml.etree.ElementTree as ET 
   3  import math 
   4  import os 
5 6 -class InvalidParamCard(Exception):
7 """ a class for invalid param_card """ 8 pass
9
10 -class Parameter (object):
11 """A class for a param_card parameter""" 12
13 - def __init__(self, param=None, block=None, lhacode=None, value=None, comment=None):
14 """Init the parameter""" 15 16 self.format = 'float' 17 if param: 18 block = param.lhablock 19 lhacode = param.lhacode 20 value = param.value 21 comment = param.comment 22 format = param.format 23 24 self.lhablock = block 25 if lhacode: 26 self.lhacode = lhacode 27 else: 28 self.lhacode = [] 29 self.value = value 30 self.comment = comment
31
32 - def set_block(self, block):
33 """ set the block name """ 34 35 self.lhablock = block
36
37 - def load_str(self, text):
38 """ initialize the information from a str""" 39 40 if '#' in text: 41 data, self.comment = text.split('#',1) 42 else: 43 data, self.comment = text, "" 44 45 46 data = data.split() 47 if not len(data): 48 return 49 try: 50 self.lhacode = tuple([int(d) for d in data[:-1]]) 51 except Exception: 52 self.lhacode = tuple([int(d) for d in data[:-1] if d.isdigit()]) 53 self.value= ' '.join(data[len(self.lhacode):]) 54 else: 55 self.value = data[-1] 56 57 # convert to number when possible 58 try: 59 self.value = float(self.value) 60 except: 61 self.format = 'str' 62 pass
63 64
65 - def load_decay(self, text):
66 """ initialize the decay information from a str""" 67 68 if '#' in text: 69 data, self.comment = text.split('#',1) 70 else: 71 data, self.comment = text, "" 72 73 74 data = data.split() 75 if not len(data): 76 return 77 self.lhacode = tuple([int(d) for d in data[1:]]) 78 self.value = float(data[0]) 79 self.format = 'decay_table'
80
81 - def __str__(self):
82 """ return a SLAH string """ 83 84 if self.format == 'float': 85 if self.lhablock == 'decay': 86 return 'DECAY %s %e # %s' % (' '.join([str(d) for d in self.lhacode]), self.value, self.comment) 87 else: 88 return ' %s %e # %s' % (' '.join([str(d) for d in self.lhacode]), self.value, self.comment) 89 elif self.format == 'str': 90 return ' %s %s # %s' % (' '.join([str(d) for d in self.lhacode]), self.value, self.comment) 91 elif self.format == 'decay_table': 92 return ' %e %s # %s' % ( self.value,' '.join([str(d) for d in self.lhacode]), self.comment) 93 94 else: 95 if self.lhablock == 'decay': 96 return 'DECAY %s %d # %s' % (' '.join([str(d) for d in self.lhacode]), self.value, self.comment) 97 else: 98 return ' %s %d # %s' % (' '.join([str(d) for d in self.lhacode]), self.value, self.comment)
99
100 101 -class Block(list):
102 """ list of parameter """ 103
104 - def __init__(self, name=None):
105 self.name = name 106 self.scale = None 107 self.comment = '' 108 self.decay_table = {} 109 self.param_dict={} 110 list.__init__(self)
111
112 - def get(self, lhacode, default=None):
113 """return the parameter associate to the lhacode""" 114 if not self.param_dict: 115 self.create_param_dict() 116 try: 117 return self.param_dict[tuple(lhacode)] 118 except KeyError: 119 if default is None: 120 raise 121 else: 122 return Parameter(block=self, lhacode=lhacode, value=default, 123 comment='not define')
124
125 - def remove(self, lhacode):
126 """ remove a parameter """ 127 list.remove(self, self.get(lhacode)) 128 # update the dictionary of key 129 return self.param_dict.pop(tuple(lhacode))
130
131 - def append(self, obj):
132 133 assert isinstance(obj, Parameter) 134 assert not obj.lhablock or obj.lhablock == self.name 135 assert tuple(obj.lhacode) not in self.param_dict, \ 136 '%s already define in %s' % (obj.lhacode,self) 137 138 list.append(self, obj) 139 # update the dictionary of key 140 self.param_dict[tuple(obj.lhacode)] = obj
141
142 - def create_param_dict(self):
143 """create a link between the lhacode and the Parameter""" 144 for param in self: 145 self.param_dict[tuple(param.lhacode)] = param 146 147 return self.param_dict
148
149 - def def_scale(self, scale):
150 """ """ 151 self.scale = scale
152
153 - def load_str(self, text):
154 "set inforamtion from the line" 155 156 if '#' in text: 157 data, self.comment = text.split('#',1) 158 else: 159 data, self.commant = text, "" 160 161 data = data.lower() 162 data = data.split() 163 self.name = data[1] # the first part of data is model 164 165 if len(data) == 3: 166 if data[2].startswith('q='): 167 #the last part should be of the form Q= 168 self.scale = float(data[2][2:]) 169 elif self.name == 'qnumbers': 170 self.name += ' %s' % data[2] 171 return self
172
173 - def keys(self):
174 """returns the list of id define in this blocks""" 175 176 return [p.lhacode for p in self]
177
178 - def __str__(self):
179 """ return a str in the SLAH format """ 180 181 text = """###################################""" + \ 182 """\n## INFORMATION FOR %s""" % self.name.upper() +\ 183 """\n###################################\n""" 184 185 #special case for decay chain 186 if self.name == 'decay': 187 for param in self: 188 id = param.lhacode[0] 189 param.set_block('decay') 190 text += str(param)+ '\n' 191 if self.decay_table.has_key(id): 192 text += str(self.decay_table[id])+'\n' 193 return text 194 elif self.name.startswith('decay'): 195 text = '' # avoid block definition 196 #general case 197 elif not self.scale: 198 text += 'BLOCK %s # %s\n' % (self.name.upper(), self.comment) 199 else: 200 text += 'BLOCK %s Q= %e # %s\n' % (self.name.upper(), self.scale, self.comment) 201 202 text += '\n'.join([str(param) for param in self]) 203 204 return text + '\n'
205
206 207 -class ParamCard(dict):
208 """ a param Card: list of Block """ 209 210 header = \ 211 """######################################################################\n""" + \ 212 """## PARAM_CARD AUTOMATICALY GENERATED BY MG5 ####\n""" + \ 213 """######################################################################\n""" 214 215
216 - def __init__(self, input_path=None):
217 self.order = [] 218 219 if input_path: 220 self.read(input_path)
221
222 - def read(self, input_path):
223 """ read a card and full this object with the content of the card """ 224 225 if isinstance(input_path, str): 226 input = open(input_path) 227 else: 228 input = input_path # helpfull for the test 229 230 231 cur_block = None 232 for line in input: 233 line = line.strip() 234 if not line or line[0] == '#': 235 continue 236 line = line.lower() 237 if line.startswith('block'): 238 cur_block = Block() 239 cur_block.load_str(line) 240 self.append(cur_block) 241 continue 242 243 if line.startswith('decay'): 244 if not self.has_block('decay'): 245 cur_block = Block('decay') 246 self.append(cur_block) 247 else: 248 cur_block = self['decay'] 249 param = Parameter() 250 param.load_str(line[6:]) 251 cur_block.append(param) 252 continue 253 254 if cur_block.name == 'decay': 255 # This is a decay table 256 id = cur_block[-1].lhacode[0] 257 cur_block = Block('decay_table_%s' % id) 258 self['decay'].decay_table[id] = cur_block 259 260 261 if cur_block is None: 262 continue 263 264 if cur_block.name.startswith('decay_table'): 265 param = Parameter() 266 param.load_decay(line) 267 cur_block.append(param) 268 else: 269 param = Parameter() 270 param.load_str(line) 271 cur_block.append(param) 272 273 return self
274
275 - def write(self, outpath):
276 """schedular for writing a card""" 277 278 # order the block in a smart way 279 blocks = self.order_block() 280 281 text = self.header 282 text += ''.join([str(block) for block in blocks]) 283 284 if isinstance(outpath, str): 285 file(outpath,'w').write(text) 286 else: 287 outpath.write(text) # for test purpose
288
289 - def append(self, object):
290 """add an object to this""" 291 292 assert isinstance(object, Block) 293 self[object.name] = object 294 if not object.name.startswith('decay_table'): 295 self.order.append(object)
296 297
298 - def has_block(self, name):
299 return self.has_key(name)
300
301 - def order_block(self):
302 """ reorganize the block """ 303 return self.order
304
305 - def rename_blocks(self, name_dict):
306 """ rename the blocks """ 307 308 for old_name, new_name in name_dict.items(): 309 self[new_name] = self.pop(old_name) 310 self[new_name].name = new_name 311 for param in self[new_name]: 312 param.lhablock = new_name
313
314 - def remove_block(self, name):
315 """ remove a blocks """ 316 assert len(self[name])==0 317 [self.order.pop(i) for i,b in enumerate(self.order) if b.name == name] 318 self.pop(name)
319
320 - def remove_param(self, block, lhacode):
321 """ remove a parameter """ 322 if self.has_param(block, lhacode): 323 self[block].remove(lhacode) 324 if len(self[block]) == 0: 325 self.remove_block(block)
326
327 - def has_param(self, block, lhacode):
328 """check if param exists""" 329 330 try: 331 self[block].get(lhacode) 332 except: 333 return False 334 else: 335 return True
336
337 - def copy_param(self,old_block, old_lha, block=None, lhacode=None):
338 """ make a parameter, a symbolic link on another one """ 339 340 # Find the current block/parameter 341 old_block_obj = self[old_block] 342 parameter = old_block_obj.get(old_lha) 343 if not block: 344 block = old_block 345 if not lhacode: 346 lhacode = old_lha 347 348 self.add_param(block, lhacode, parameter.value, parameter.comment)
349
350 - def add_param(self,block, lha, value, comment=''):
351 352 parameter = Parameter(block=block, lhacode=lha, value=value, 353 comment=comment) 354 355 try: 356 new_block = self[block] 357 except KeyError: 358 # If the new block didn't exist yet 359 new_block = Block(block) 360 self.append(new_block) 361 new_block.append(parameter)
362 363
364 - def mod_param(self, old_block, old_lha, block=None, lhacode=None, 365 value=None, comment=None):
366 """ change a parameter to a new one. This is not a duplication.""" 367 368 # Find the current block/parameter 369 old_block = self[old_block] 370 parameter = old_block.get(old_lha) 371 372 # Update the parameter 373 if block: 374 parameter.lhablock = block 375 if lhacode: 376 parameter.lhacode = lhacode 377 if value: 378 parameter.value = value 379 if comment: 380 parameter.comment = comment 381 382 # Change the block of the parameter 383 if block: 384 old_block.remove(old_lha) 385 if not len(old_block): 386 self.remove_block(old_block.name) 387 try: 388 new_block = self[block] 389 except KeyError: 390 # If the new block didn't exist yet 391 new_block = Block(block) 392 self.append(new_block) 393 new_block.append(parameter) 394 elif lhacode: 395 old_block.param_dict[tuple(lhacode)] = \ 396 old_block.param_dict.pop(tuple(old_lha))
397 398
399 - def check_and_remove(self, block, lhacode, value):
400 """ check that the value is coherent and remove it""" 401 402 if self.has_param(block, lhacode): 403 param = self[block].get(lhacode) 404 if param.value != value: 405 error_msg = 'This card is not suitable to be convert to SLAH1\n' 406 error_msg += 'Parameter %s %s should be %s' % (block, lhacode, value) 407 raise InvalidParamCard, error_msg 408 self.remove_param(block, lhacode)
409
410 -class ParamCardRule(object):
411 """ A class for storing the linked between the different parameter of 412 the param_card. 413 Able to write a file 'param_card_rule.dat' 414 Able to read a file 'param_card_rule.dat' 415 Able to check the validity of a param_card.dat 416 """ 417 418
419 - def __init__(self, inputpath=None):
420 """initialize an object """ 421 422 # constraint due to model restriction 423 self.zero = [] 424 self.one = [] 425 self.identical = [] 426 self.opposite = [] 427 428 # constraint due to the model 429 self.rule = [] 430 431 if inputpath: 432 self.load_rule(inputpath)
433
434 - def add_zero(self, lhablock, lhacode, comment=''):
435 """add a zero rule""" 436 self.zero.append( (lhablock, lhacode, comment) )
437
438 - def add_one(self, lhablock, lhacode, comment=''):
439 """add a one rule""" 440 self.one.append( (lhablock, lhacode, comment) )
441
442 - def add_identical(self, lhablock, lhacode, lhacode2, comment=''):
443 """add a rule for identical value""" 444 self.identical.append( (lhablock, lhacode, lhacode2, comment) )
445
446 - def add_opposite(self, lhablock, lhacode, lhacode2, comment=''):
447 """add a rule for identical value""" 448 self.opposite.append( (lhablock, lhacode, lhacode2, comment) )
449 450
451 - def add_rule(self, lhablock, lhacode, rule, comment=''):
452 """add a rule for constraint value""" 453 self.rule.append( (lhablock, lhacode, rule) )
454
455 - def write_file(self, output=None):
456 457 text = """<file>###################################################################### 458 ## VALIDITY RULE FOR THE PARAM_CARD #### 459 ######################################################################\n""" 460 461 # ZERO 462 text +='<zero>\n' 463 for name, id, comment in self.zero: 464 text+=' %s %s # %s\n' % (name, ' '.join([str(i) for i in id]), 465 comment) 466 # ONE 467 text +='</zero>\n<one>\n' 468 for name, id, comment in self.one: 469 text+=' %s %s # %s\n' % (name, ' '.join([str(i) for i in id]), 470 comment) 471 # IDENTICAL 472 text +='</one>\n<identical>\n' 473 for name, id,id2, comment in self.identical: 474 text+=' %s %s : %s # %s\n' % (name, ' '.join([str(i) for i in id]), 475 ' '.join([str(i) for i in id2]), comment) 476 477 # OPPOSITE 478 text +='</identical>\n<opposite>\n' 479 for name, id,id2, comment in self.opposite: 480 text+=' %s %s : %s # %s\n' % (name, ' '.join([str(i) for i in id]), 481 ' '.join([str(i) for i in id2]), comment) 482 483 # CONSTRAINT 484 text += '</opposite>\n<constraint>\n' 485 for name, id, rule, comment in self.rule: 486 text += ' %s %s : %s # %s\n' % (name, ' '.join([str(i) for i in id]), 487 rule, comment) 488 text += '</constraint>\n</file>' 489 490 if isinstance(output, str): 491 output = open(output,'w') 492 if hasattr(output, 'write'): 493 output.write(text) 494 return text
495
496 - def load_rule(self, inputpath):
497 """ import a validity rule file """ 498 499 500 try: 501 tree = ET.parse(inputpath) 502 except IOError: 503 if '\n' in inputpath: 504 # this is convinient for the tests 505 tree = ET.fromstring(inputpath) 506 else: 507 raise 508 509 #Add zero element 510 element = tree.find('zero') 511 if element is not None: 512 for line in element.text.split('\n'): 513 line = line.split('#',1)[0] 514 if not line: 515 continue 516 lhacode = line.split() 517 blockname = lhacode.pop(0) 518 lhacode = [int(code) for code in lhacode ] 519 self.add_zero(blockname, lhacode, '') 520 521 #Add one element 522 element = tree.find('one') 523 if element is not None: 524 for line in element.text.split('\n'): 525 line = line.split('#',1)[0] 526 if not line: 527 continue 528 lhacode = line.split() 529 blockname = lhacode.pop(0) 530 lhacode = [int(code) for code in lhacode ] 531 self.add_one(blockname, lhacode, '') 532 533 #Add Identical element 534 element = tree.find('identical') 535 if element is not None: 536 for line in element.text.split('\n'): 537 line = line.split('#',1)[0] 538 if not line: 539 continue 540 line, lhacode2 = line.split(':') 541 lhacode = line.split() 542 blockname = lhacode.pop(0) 543 lhacode = [int(code) for code in lhacode ] 544 lhacode2 = [int(code) for code in lhacode2.split() ] 545 self.add_identical(blockname, lhacode, lhacode2, '') 546 547 #Add Opposite element 548 element = tree.find('opposite') 549 if element is not None: 550 for line in element.text.split('\n'): 551 line = line.split('#',1)[0] 552 if not line: 553 continue 554 line, lhacode2 = line.split(':') 555 lhacode = line.split() 556 blockname = lhacode.pop(0) 557 lhacode = [int(code) for code in lhacode ] 558 lhacode2 = [int(code) for code in lhacode2.split() ] 559 self.add_opposite(blockname, lhacode, lhacode2, '') 560 561 #Add Rule element 562 element = tree.find('rule') 563 if element is not None: 564 for line in element.text.split('\n'): 565 line = line.split('#',1)[0] 566 if not line: 567 continue 568 line, rule = line.split(':') 569 lhacode = line.split() 570 blockname = lhacode.pop(0) 571 self.add_rule(blockname, lhacode, rule, '')
572 573 @staticmethod
574 - def read_param_card(path):
575 """ read a param_card and return a dictionary with the associated value.""" 576 577 output = ParamCard(path) 578 579 580 581 return output
582 583 @staticmethod
584 - def write_param_card(path, data):
585 """ read a param_card and return a dictionary with the associated value.""" 586 587 output = {} 588 589 if isinstance(path, str): 590 output = open(path, 'w') 591 else: 592 output = path # helpfull for the test 593 594 data.write(path)
595 596
597 - def check_param_card(self, path, modify=False):
598 """Check that the restriction card are applied""" 599 600 card = self.read_param_card(path) 601 602 # check zero 603 for block, id, comment in self.zero: 604 try: 605 value = float(card[block].get(id).value) 606 except KeyError: 607 if modify: 608 new_param = Parameter(block=block,lhacode=id, value=0, 609 comment='fixed by the model') 610 if block in card: 611 card[block].append(new_param) 612 else: 613 new_block = Block(block) 614 card.append(new_block) 615 new_block.append(new_param) 616 else: 617 if value != 0: 618 if not modify: 619 raise InvalidParamCard, 'parameter %s: %s is not at zero' % \ 620 (block, ' '.join([str(i) for i in id])) 621 else: 622 param = card[block].get(id) 623 param.value = 0.0 624 param.comment += ' fixed by the model' 625 626 # check one 627 for block, id, comment in self.one: 628 try: 629 value = card[block].get(id).value 630 except KeyError: 631 if modify: 632 new_param = Parameter(block=block,lhacode=id, value=1, 633 comment='fixed by the model') 634 if block in card: 635 card[block].append(new_param) 636 else: 637 new_block = Block(block) 638 card.append(new_block) 639 new_block.append(new_param) 640 else: 641 if value != 1: 642 if not modify: 643 raise InvalidParamCard, 'parameter %s: %s is not at one but at %s' % \ 644 (block, ' '.join([str(i) for i in id]), value) 645 else: 646 param = card[block].get(id) 647 param.value = 1.0 648 param.comment += ' fixed by the model' 649 650 651 # check identical 652 for block, id1, id2, comment in self.identical: 653 value2 = float(card[block].get(id2).value) 654 try: 655 param = card[block].get(id1) 656 except KeyError: 657 if modify: 658 new_param = Parameter(block=block,lhacode=id1, value=value2, 659 comment='must be identical to %s' %id2) 660 card[block].append(new_param) 661 else: 662 value1 = float(param.value) 663 664 if value1 != value2: 665 if not modify: 666 raise InvalidParamCard, 'parameter %s: %s is not to identical to parameter %s' % \ 667 (block, ' '.join([str(i) for i in id1]), 668 ' '.join([str(i) for i in id2])) 669 else: 670 param = card[block].get(id1) 671 param.value = value2 672 param.comment += ' must be identical to %s' % id2 673 674 # check opposite 675 for block, id1, id2, comment in self.opposite: 676 value2 = float(card[block].get(id2).value) 677 try: 678 param = card[block].get(id1) 679 except KeyError: 680 if modify: 681 new_param = Parameter(block=block,lhacode=id1, value=-value2, 682 comment='must be opposite to to %s' %id2) 683 card[block].append(new_param) 684 else: 685 value1 = float(param.value) 686 687 if value1 != -value2: 688 if not modify: 689 raise InvalidParamCard, 'parameter %s: %s is not to opposite to parameter %s' % \ 690 (block, ' '.join([str(i) for i in id1]), 691 ' '.join([str(i) for i in id2])) 692 else: 693 param = card[block].get(id1) 694 param.value = -value2 695 param.comment += ' must be opposite to %s' % id2 696 697 return card
698
699 700 -def convert_to_slha1(path, outputpath=None ):
701 """ """ 702 703 if not outputpath: 704 outputpath = path 705 card = ParamCard(path) 706 707 708 # Mass 709 #card.reorder_mass() # needed? 710 card.copy_param('mass', [6], 'sminputs', [6]) 711 card.copy_param('mass', [15], 'sminputs', [7]) 712 card.copy_param('mass', [23], 'sminputs', [4]) 713 # Decay: Nothing to do. 714 715 # MODSEL 716 card.add_param('modsel',[1], value=1) 717 card['modsel'].get([1]).format = 'int' 718 719 # find scale 720 scale = card['hmix'].scale 721 if not scale: 722 scale = 1 # Need to be define (this is dummy value) 723 724 # SMINPUTS 725 if not card.has_param('sminputs', [2]): 726 aem1 = card['sminputs'].get([1]).value 727 mz = card['mass'].get([23]).value 728 mw = card['mass'].get([24]).value 729 gf = math.pi / math.sqrt(2) / aem1 * mz**2/ mw**2 /(mz**2-mw**2) 730 card.add_param('sminputs', [2], gf, 'G_F [GeV^-2]') 731 732 # USQMIX 733 card.check_and_remove('usqmix', [1,1], 1.0) 734 card.check_and_remove('usqmix', [2,2], 1.0) 735 card.check_and_remove('usqmix', [4,4], 1.0) 736 card.check_and_remove('usqmix', [5,5], 1.0) 737 card.mod_param('usqmix', [3,3], 'stopmix', [1,1]) 738 card.mod_param('usqmix', [3,6], 'stopmix', [1,2]) 739 card.mod_param('usqmix', [6,3], 'stopmix', [2,1]) 740 card.mod_param('usqmix', [6,6], 'stopmix', [2,2]) 741 742 # DSQMIX 743 card.check_and_remove('dsqmix', [1,1], 1.0) 744 card.check_and_remove('dsqmix', [2,2], 1.0) 745 card.check_and_remove('dsqmix', [4,4], 1.0) 746 card.check_and_remove('dsqmix', [5,5], 1.0) 747 card.mod_param('dsqmix', [3,3], 'sbotmix', [1,1]) 748 card.mod_param('dsqmix', [3,6], 'sbotmix', [1,2]) 749 card.mod_param('dsqmix', [6,3], 'sbotmix', [2,1]) 750 card.mod_param('dsqmix', [6,6], 'sbotmix', [2,2]) 751 752 753 # SELMIX 754 card.check_and_remove('selmix', [1,1], 1.0) 755 card.check_and_remove('selmix', [2,2], 1.0) 756 card.check_and_remove('selmix', [4,4], 1.0) 757 card.check_and_remove('selmix', [5,5], 1.0) 758 card.mod_param('selmix', [3,3], 'staumix', [1,1]) 759 card.mod_param('selmix', [3,6], 'staumix', [1,2]) 760 card.mod_param('selmix', [6,3], 'staumix', [2,1]) 761 card.mod_param('selmix', [6,6], 'staumix', [2,2]) 762 763 # FRALPHA 764 card.mod_param('fralpha', [1], 'alpha', [' ']) 765 766 #HMIX 767 if not card.has_param('hmix', [3]): 768 aem1 = card['sminputs'].get([1]).value 769 tanb = card['hmix'].get([2]).value 770 mz = card['mass'].get([23]).value 771 mw = card['mass'].get([24]).value 772 sw = math.sqrt(mz**2 - mw**2)/mz 773 ee = 2 * math.sqrt(1/aem1) * math.sqrt(math.pi) 774 vu = 2 * mw *sw /ee * math.sin(math.atan(tanb)) 775 card.add_param('hmix', [3], vu, 'higgs vev(Q) MSSM DRb') 776 card['hmix'].scale= scale 777 778 # VCKM 779 card.check_and_remove('vckm', [1,1], 1.0) 780 card.check_and_remove('vckm', [2,2], 1.0) 781 card.check_and_remove('vckm', [3,3], 1.0) 782 783 #SNUMIX 784 card.check_and_remove('snumix', [1,1], 1.0) 785 card.check_and_remove('snumix', [2,2], 1.0) 786 card.check_and_remove('snumix', [3,3], 1.0) 787 788 #UPMNS 789 card.check_and_remove('upmns', [1,1], 1.0) 790 card.check_and_remove('upmns', [2,2], 1.0) 791 card.check_and_remove('upmns', [3,3], 1.0) 792 793 # Te 794 ye = card['ye'].get([3, 3]).value 795 te = card['te'].get([3, 3]).value 796 card.mod_param('te', [3,3], 'ae', [3,3], value= te/ye, comment='A_tau(Q) DRbar') 797 card.add_param('ae', [1,1], 0, 'A_e(Q) DRbar') 798 card.add_param('ae', [2,2], 0, 'A_mu(Q) DRbar') 799 card['ae'].scale = scale 800 card['ye'].scale = scale 801 802 # Tu 803 yu = card['yu'].get([3, 3]).value 804 tu = card['tu'].get([3, 3]).value 805 card.mod_param('tu', [3,3], 'au', [3,3], value= tu/yu, comment='A_t(Q) DRbar') 806 card.add_param('au', [1,1], 0, 'A_u(Q) DRbar') 807 card.add_param('au', [2,2], 0, 'A_c(Q) DRbar') 808 card['au'].scale = scale 809 card['yu'].scale = scale 810 811 # Td 812 yd = card['yd'].get([3, 3]).value 813 td = card['td'].get([3, 3]).value 814 card.mod_param('td', [3,3], 'ad', [3,3], value= td/yd, comment='A_b(Q) DRbar') 815 card.add_param('ad', [1,1], 0, 'A_d(Q) DRbar') 816 card.add_param('ad', [2,2], 0, 'A_s(Q) DRbar') 817 card['ad'].scale = scale 818 card['yd'].scale = scale 819 820 # MSL2 821 value = card['msl2'].get([1, 1]).value 822 card.mod_param('msl2', [1,1], 'msoft', [31], math.sqrt(value)) 823 value = card['msl2'].get([2, 2]).value 824 card.mod_param('msl2', [2,2], 'msoft', [32], math.sqrt(value)) 825 value = card['msl2'].get([3, 3]).value 826 card.mod_param('msl2', [3,3], 'msoft', [33], math.sqrt(value)) 827 card['msoft'].scale = scale 828 829 # MSE2 830 value = card['mse2'].get([1, 1]).value 831 card.mod_param('mse2', [1,1], 'msoft', [34], math.sqrt(value)) 832 value = card['mse2'].get([2, 2]).value 833 card.mod_param('mse2', [2,2], 'msoft', [35], math.sqrt(value)) 834 value = card['mse2'].get([3, 3]).value 835 card.mod_param('mse2', [3,3], 'msoft', [36], math.sqrt(value)) 836 837 # MSQ2 838 value = card['msq2'].get([1, 1]).value 839 card.mod_param('msq2', [1,1], 'msoft', [41], math.sqrt(value)) 840 value = card['msq2'].get([2, 2]).value 841 card.mod_param('msq2', [2,2], 'msoft', [42], math.sqrt(value)) 842 value = card['msq2'].get([3, 3]).value 843 card.mod_param('msq2', [3,3], 'msoft', [43], math.sqrt(value)) 844 845 # MSU2 846 value = card['msu2'].get([1, 1]).value 847 card.mod_param('msu2', [1,1], 'msoft', [44], math.sqrt(value)) 848 value = card['msu2'].get([2, 2]).value 849 card.mod_param('msu2', [2,2], 'msoft', [45], math.sqrt(value)) 850 value = card['msu2'].get([3, 3]).value 851 card.mod_param('msu2', [3,3], 'msoft', [46], math.sqrt(value)) 852 853 # MSD2 854 value = card['msd2'].get([1, 1]).value 855 card.mod_param('msd2', [1,1], 'msoft', [47], math.sqrt(value)) 856 value = card['msd2'].get([2, 2]).value 857 card.mod_param('msd2', [2,2], 'msoft', [48], math.sqrt(value)) 858 value = card['msd2'].get([3, 3]).value 859 card.mod_param('msd2', [3,3], 'msoft', [49], math.sqrt(value)) 860 861 862 863 ################# 864 # WRITE OUTPUT 865 ################# 866 card.write(outputpath)
867
868 869 870 -def convert_to_mg5card(path, outputpath=None ):
871 """ """ 872 873 if not outputpath: 874 outputpath = path 875 card = ParamCard(path) 876 877 878 # SMINPUTS 879 card.remove_param('sminputs', [2]) 880 card.remove_param('sminputs', [4]) 881 card.remove_param('sminputs', [6]) 882 card.remove_param('sminputs', [7]) 883 # Decay: Nothing to do. 884 885 # MODSEL 886 card.remove_param('modsel',[1]) 887 888 889 # USQMIX 890 card.add_param('usqmix', [1,1], 1.0) 891 card.add_param('usqmix', [2,2], 1.0) 892 card.add_param('usqmix', [4,4], 1.0) 893 card.add_param('usqmix', [5,5], 1.0) 894 card.mod_param('stopmix', [1,1], 'usqmix', [3,3]) 895 card.mod_param('stopmix', [1,2], 'usqmix', [3,6]) 896 card.mod_param('stopmix', [2,1], 'usqmix', [6,3]) 897 card.mod_param('stopmix', [2,2], 'usqmix', [6,6]) 898 899 # DSQMIX 900 card.add_param('dsqmix', [1,1], 1.0) 901 card.add_param('dsqmix', [2,2], 1.0) 902 card.add_param('dsqmix', [4,4], 1.0) 903 card.add_param('dsqmix', [5,5], 1.0) 904 card.mod_param('sbotmix', [1,1], 'dsqmix', [3,3]) 905 card.mod_param('sbotmix', [1,2], 'dsqmix', [3,6]) 906 card.mod_param('sbotmix', [2,1], 'dsqmix', [6,3]) 907 card.mod_param('sbotmix', [2,2], 'dsqmix', [6,6]) 908 909 910 # SELMIX 911 card.add_param('selmix', [1,1], 1.0) 912 card.add_param('selmix', [2,2], 1.0) 913 card.add_param('selmix', [4,4], 1.0) 914 card.add_param('selmix', [5,5], 1.0) 915 card.mod_param('staumix', [1,1], 'selmix', [3,3]) 916 card.mod_param('staumix', [1,2], 'selmix', [3,6]) 917 card.mod_param('staumix', [2,1], 'selmix', [6,3]) 918 card.mod_param('staumix', [2,2], 'selmix', [6,6]) 919 920 # FRALPHA 921 card.mod_param('alpha', [], 'fralpha', [1]) 922 923 #HMIX 924 card.remove_param('hmix', [3]) 925 926 # VCKM 927 card.add_param('vckm', [1,1], 1.0) 928 card.add_param('vckm', [2,2], 1.0) 929 card.add_param('vckm', [3,3], 1.0) 930 931 #SNUMIX 932 card.add_param('snumix', [1,1], 1.0) 933 card.add_param('snumix', [2,2], 1.0) 934 card.add_param('snumix', [3,3], 1.0) 935 936 #UPMNS 937 card.add_param('upmns', [1,1], 1.0) 938 card.add_param('upmns', [2,2], 1.0) 939 card.add_param('upmns', [3,3], 1.0) 940 941 # Te 942 ye = card['ye'].get([1, 1], default=0).value 943 ae = card['ae'].get([1, 1], default=0).value 944 card.mod_param('ae', [1,1], 'te', [1,1], value= ae * ye, comment='T_e(Q) DRbar') 945 if ae * ye: 946 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model 947 Parameter ae [1, 1] times ye [1,1] should be 0''' 948 card.remove_param('ae', [1,1]) 949 #2 950 ye = card['ye'].get([2, 2], default=0).value 951 952 ae = card['ae'].get([2, 2], default=0).value 953 card.mod_param('ae', [2,2], 'te', [2,2], value= ae * ye, comment='T_mu(Q) DRbar') 954 if ae * ye: 955 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model 956 Parameter ae [2, 2] times ye [2,2] should be 0''' 957 card.remove_param('ae', [2,2]) 958 #3 959 ye = card['ye'].get([3, 3], default=0).value 960 ae = card['ae'].get([3, 3], default=0).value 961 card.mod_param('ae', [3,3], 'te', [3,3], value= ae * ye, comment='T_tau(Q) DRbar') 962 963 # Tu 964 yu = card['yu'].get([1, 1], default=0).value 965 au = card['au'].get([1, 1], default=0).value 966 card.mod_param('au', [1,1], 'tu', [1,1], value= au * yu, comment='T_u(Q) DRbar') 967 if au * yu: 968 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model 969 Parameter au [1, 1] times yu [1,1] should be 0''' 970 card.remove_param('au', [1,1]) 971 #2 972 ye = card['yu'].get([2, 2], default=0).value 973 974 ae = card['au'].get([2, 2], default=0).value 975 card.mod_param('au', [2,2], 'tu', [2,2], value= au * yu, comment='T_c(Q) DRbar') 976 if au * yu: 977 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model 978 Parameter au [2, 2] times yu [2,2] should be 0''' 979 card.remove_param('au', [2,2]) 980 #3 981 yu = card['yu'].get([3, 3]).value 982 au = card['au'].get([3, 3]).value 983 card.mod_param('au', [3,3], 'tu', [3,3], value= au * yu, comment='T_t(Q) DRbar') 984 985 # Td 986 yd = card['yd'].get([1, 1], default=0).value 987 ad = card['ad'].get([1, 1], default=0).value 988 card.mod_param('ad', [1,1], 'td', [1,1], value= ad * yd, comment='T_d(Q) DRbar') 989 if ad * yd: 990 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model 991 Parameter ad [1, 1] times yd [1,1] should be 0''' 992 card.remove_param('ad', [1,1]) 993 #2 994 ye = card['yd'].get([2, 2], default=0).value 995 996 ae = card['ad'].get([2, 2], default=0).value 997 card.mod_param('ad', [2,2], 'td', [2,2], value= ad * yd, comment='T_s(Q) DRbar') 998 if ad * yd: 999 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model 1000 Parameter ad [2, 2] times yd [2,2] should be 0''' 1001 card.remove_param('ad', [2,2]) 1002 #3 1003 yd = card['yd'].get([3, 3]).value 1004 ad = card['ad'].get([3, 3]).value 1005 card.mod_param('ad', [3,3], 'td', [3,3], value= ad * yd, comment='T_b(Q) DRbar') 1006 1007 1008 # MSL2 1009 value = card['msoft'].get([31]).value 1010 card.mod_param('msoft', [31], 'msl2', [1,1], value**2) 1011 value = card['msoft'].get([32]).value 1012 card.mod_param('msoft', [32], 'msl2', [2,2], value**2) 1013 value = card['msoft'].get([33]).value 1014 card.mod_param('msoft', [33], 'msl2', [3,3], value**2) 1015 1016 # MSE2 1017 value = card['msoft'].get([34]).value 1018 card.mod_param('msoft', [34], 'mse2', [1,1], value**2) 1019 value = card['msoft'].get([35]).value 1020 card.mod_param('msoft', [35], 'mse2', [2,2], value**2) 1021 value = card['msoft'].get([36]).value 1022 card.mod_param('msoft', [36], 'mse2', [3,3], value**2) 1023 1024 # MSQ2 1025 value = card['msoft'].get([41]).value 1026 card.mod_param('msoft', [41], 'msq2', [1,1], value**2) 1027 value = card['msoft'].get([42]).value 1028 card.mod_param('msoft', [42], 'msq2', [2,2], value**2) 1029 value = card['msoft'].get([43]).value 1030 card.mod_param('msoft', [43], 'msq2', [3,3], value**2) 1031 1032 # MSU2 1033 value = card['msoft'].get([44]).value 1034 card.mod_param('msoft', [44], 'msu2', [1,1], value**2) 1035 value = card['msoft'].get([45]).value 1036 card.mod_param('msoft', [45], 'msu2', [2,2], value**2) 1037 value = card['msoft'].get([46]).value 1038 card.mod_param('msoft', [46], 'msu2', [3,3], value**2) 1039 1040 # MSD2 1041 value = card['msoft'].get([47]).value 1042 card.mod_param('msoft', [47], 'msd2', [1,1], value**2) 1043 value = card['msoft'].get([48]).value 1044 card.mod_param('msoft', [48], 'msd2', [2,2], value**2) 1045 value = card['msoft'].get([49]).value 1046 card.mod_param('msoft', [49], 'msd2', [3,3], value**2) 1047 1048 ################# 1049 # WRITE OUTPUT 1050 ################# 1051 card.write(outputpath)
1052
1053 1054 1055 -def make_valid_param_card(path, restrictpath, outputpath=None):
1056 """ modify the current param_card such that it agrees with the restriction""" 1057 1058 if not outputpath: 1059 outputpath = path 1060 1061 cardrule = ParamCardRule() 1062 cardrule.load_rule(restrictpath) 1063 try : 1064 cardrule.check_param_card(path, modify=False) 1065 except InvalidParamCard: 1066 new_data = cardrule.check_param_card(path, modify=True) 1067 cardrule.write_param_card(outputpath, new_data) 1068 else: 1069 if path != outputpath: 1070 shutil.copy(path, outputpath) 1071 return cardrule
1072
1073 -def check_valid_param_card(path, restrictpath=None):
1074 """ check if the current param_card agrees with the restriction""" 1075 1076 if restrictpath is None: 1077 restrictpath = os.path.dirname(path) 1078 restrictpath = os.path.join(restrictpath, os.pardir, os.pardir, 'Source', 1079 'MODEL', 'param_card_rule.dat') 1080 if not os.path.exists(restrictpath): 1081 print 'no restriction card' 1082 return True 1083 1084 cardrule = ParamCardRule() 1085 cardrule.load_rule(restrictpath) 1086 cardrule.check_param_card(path, modify=False)
1087 1088 if '__main__' == __name__: 1089 1090 1091 make_valid_param_card('./Cards/param_card.dat', './Source/MODEL/param_card_rule.dat', 1092 outputpath='tmp1.dat') 1093 convert_to_slha1('tmp1.dat' , './param_card.dat') 1094