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   
   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   
  12  logger = logging.getLogger('madgraph.models') # -> stdout 
  13   
  14  try: 
  15      import madgraph.iolibs.file_writers as file_writers 
  16      import madgraph.various.misc as misc     
  17  except: 
  18      import internal.file_writers as file_writers 
  19      import internal.misc as misc 
  20   
  21  import StringIO 
22 23 -class InvalidParamCard(Exception):
24 """ a class for invalid param_card """ 25 pass
26
27 -class Parameter (object):
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
49 - def set_block(self, block):
50 """ set the block name """ 51 52 self.lhablock = block
53
54 - def load_str(self, text):
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 # convert to number when possible 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
88 - def load_decay(self, text):
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
107 - def __str__(self):
108 """ return a SLAH string """ 109 110 format = self.format 111 if self.format == 'float': 112 try: 113 value = float(self.value) 114 except: 115 format = 'str' 116 117 self.comment = self.comment.strip() 118 if format == 'float': 119 if self.lhablock == 'decay' and not isinstance(self.value,basestring): 120 return 'DECAY %s %e # %s' % (' '.join([str(d) for d in self.lhacode]), self.value, self.comment) 121 elif self.lhablock == 'decay': 122 return 'DECAY %s Auto # %s' % (' '.join([str(d) for d in self.lhacode]), self.comment) 123 elif self.lhablock and self.lhablock.startswith('qnumbers'): 124 return ' %s %i # %s' % (' '.join([str(d) for d in self.lhacode]), int(self.value), self.comment) 125 else: 126 return ' %s %e # %s' % (' '.join([str(d) for d in self.lhacode]), self.value, self.comment) 127 elif format == 'int': 128 return ' %s %i # %s' % (' '.join([str(d) for d in self.lhacode]), int(self.value), self.comment) 129 elif format == 'str': 130 if self.lhablock == 'decay': 131 return 'DECAY %s %s # %s' % (' '.join([str(d) for d in self.lhacode]),self.value, self.comment) 132 return ' %s %s # %s' % (' '.join([str(d) for d in self.lhacode]), self.value, self.comment) 133 elif self.format == 'decay_table': 134 return ' %e %s # %s' % ( self.value,' '.join([str(d) for d in self.lhacode]), self.comment) 135 elif self.format == 'int': 136 return ' %s %i # %s' % (' '.join([str(d) for d in self.lhacode]), int(self.value), self.comment) 137 else: 138 if self.lhablock == 'decay': 139 return 'DECAY %s %d # %s' % (' '.join([str(d) for d in self.lhacode]), self.value, self.comment) 140 else: 141 return ' %s %d # %s' % (' '.join([str(d) for d in self.lhacode]), self.value, self.comment)
142
143 144 -class Block(list):
145 """ list of parameter """ 146
147 - def __init__(self, name=None):
148 if name: 149 self.name = name.lower() 150 else: 151 self.name = name 152 self.scale = None 153 self.comment = '' 154 self.decay_table = {} 155 self.param_dict={} 156 list.__init__(self)
157
158 - def get(self, lhacode, default=None):
159 """return the parameter associate to the lhacode""" 160 if not self.param_dict: 161 self.create_param_dict() 162 163 if isinstance(lhacode, int): 164 lhacode = (lhacode,) 165 166 try: 167 return self.param_dict[tuple(lhacode)] 168 except KeyError: 169 if default is None: 170 raise KeyError, 'id %s is not in %s' % (tuple(lhacode), self.name) 171 else: 172 return Parameter(block=self, lhacode=lhacode, value=default, 173 comment='not define')
174
175 - def remove(self, lhacode):
176 """ remove a parameter """ 177 list.remove(self, self.get(lhacode)) 178 # update the dictionary of key 179 return self.param_dict.pop(tuple(lhacode))
180
181 - def __eq__(self, other, prec=1e-4):
182 """ """ 183 if len(self) != len(other): 184 return False 185 186 return not any(abs(param.value-other.param_dict[key].value)> prec * abs(param.value) 187 for key, param in self.param_dict.items())
188
189 - def __ne__(self, other, prec=1e-4):
190 return not self.__eq__(other, prec)
191
192 - def append(self, obj):
193 194 assert isinstance(obj, Parameter) 195 if not hasattr(self, 'name'): #can happen if loeaded from pickle 196 self.__init__(obj.lhablock) 197 assert not obj.lhablock or obj.lhablock == self.name 198 199 #The following line seems/is stupid but allow to pickle/unpickle this object 200 #this is important for madspin (in gridpack mode) 201 if not hasattr(self, 'param_dict'): 202 self.param_dict = {} 203 204 if tuple(obj.lhacode) in self.param_dict: 205 if self.param_dict[tuple(obj.lhacode)].value != obj.value: 206 raise InvalidParamCard, '%s %s is already define to %s impossible to assign %s' % \ 207 (self.name, obj.lhacode, self.param_dict[tuple(obj.lhacode)].value, obj.value) 208 return 209 list.append(self, obj) 210 # update the dictionary of key 211 self.param_dict[tuple(obj.lhacode)] = obj
212
213 - def create_param_dict(self):
214 """create a link between the lhacode and the Parameter""" 215 for param in self: 216 self.param_dict[tuple(param.lhacode)] = param 217 218 return self.param_dict
219
220 - def def_scale(self, scale):
221 """ """ 222 self.scale = scale
223
224 - def load_str(self, text):
225 "set inforamtion from the line" 226 227 if '#' in text: 228 data, self.comment = text.split('#',1) 229 else: 230 data, self.commant = text, "" 231 232 data = data.lower() 233 data = data.split() 234 self.name = data[1] # the first part of data is model 235 if len(data) == 3: 236 if data[2].startswith('q='): 237 #the last part should be of the form Q= 238 self.scale = float(data[2][2:]) 239 elif self.name == 'qnumbers': 240 self.name += ' %s' % data[2] 241 elif len(data) == 4 and data[2] == 'q=': 242 #the last part should be of the form Q= 243 self.scale = float(data[3]) 244 245 return self
246
247 - def keys(self):
248 """returns the list of id define in this blocks""" 249 250 return [p.lhacode for p in self]
251
252 - def __str__(self):
253 """ return a str in the SLAH format """ 254 255 text = """###################################""" + \ 256 """\n## INFORMATION FOR %s""" % self.name.upper() +\ 257 """\n###################################\n""" 258 259 #special case for decay chain 260 if self.name == 'decay': 261 for param in self: 262 pid = param.lhacode[0] 263 param.set_block('decay') 264 text += str(param)+ '\n' 265 if self.decay_table.has_key(pid): 266 text += str(self.decay_table[pid])+'\n' 267 return text 268 elif self.name.startswith('decay'): 269 text = '' # avoid block definition 270 #general case 271 elif not self.scale: 272 text += 'BLOCK %s # %s\n' % (self.name.upper(), self.comment) 273 else: 274 text += 'BLOCK %s Q= %e # %s\n' % (self.name.upper(), self.scale, self.comment) 275 276 text += '\n'.join([str(param) for param in self]) 277 return text + '\n'
278
279 280 -class ParamCard(dict):
281 """ a param Card: list of Block """ 282 mp_prefix = 'MP__' 283 284 header = \ 285 """######################################################################\n""" + \ 286 """## PARAM_CARD AUTOMATICALY GENERATED BY MG5 ####\n""" + \ 287 """######################################################################\n""" 288 289
290 - def __init__(self, input_path=None):
291 self.order = [] 292 293 if isinstance(input_path, ParamCard): 294 self.read(input_path.write()) 295 self.input_path = input_path.input_path 296 else: 297 self.input_path = input_path 298 if input_path: 299 self.read(input_path)
300
301 - def read(self, input_path):
302 """ read a card and full this object with the content of the card """ 303 304 if isinstance(input_path, str): 305 if '\n' in input_path: 306 input = StringIO.StringIO(input_path) 307 else: 308 input = open(input_path) 309 else: 310 input = input_path #Use for banner loading and test 311 312 313 cur_block = None 314 for line in input: 315 line = line.strip() 316 if not line or line[0] == '#': 317 continue 318 line = line.lower() 319 if line.startswith('block'): 320 cur_block = Block() 321 cur_block.load_str(line) 322 self.append(cur_block) 323 continue 324 325 if line.startswith('decay'): 326 if not self.has_block('decay'): 327 cur_block = Block('decay') 328 self.append(cur_block) 329 else: 330 cur_block = self['decay'] 331 param = Parameter() 332 param.set_block(cur_block.name) 333 param.load_str(line[6:]) 334 cur_block.append(param) 335 continue 336 337 if cur_block is None: 338 continue 339 340 if cur_block.name == 'decay': 341 # This is a decay table 342 id = cur_block[-1].lhacode[0] 343 cur_block = Block('decay_table_%s' % id) 344 self['decay'].decay_table[id] = cur_block 345 346 347 348 349 if cur_block.name.startswith('decay_table'): 350 param = Parameter() 351 param.load_decay(line) 352 try: 353 cur_block.append(param) 354 except InvalidParamCard: 355 pass 356 else: 357 param = Parameter() 358 param.set_block(cur_block.name) 359 param.load_str(line) 360 cur_block.append(param) 361 362 return self
363
364 - def analyze_param_card(self):
365 """ Analyzes the comment of the parameter in the param_card and returns 366 a dictionary with parameter names in values and the tuple (lhablock, id) 367 in value as well as a dictionary for restricted values. 368 WARNING: THIS FUNCTION RELIES ON THE FORMATTING OF THE COMMENT IN THE 369 CARD TO FETCH THE PARAMETER NAME. This is mostly ok on the *_default.dat 370 but typically dangerous on the user-defined card.""" 371 372 pname2block = {} 373 restricted_value = {} 374 375 for bname, block in self.items(): 376 for lha_id, param in block.param_dict.items(): 377 all_var = [] 378 comment = param.comment 379 # treat merge parameter 380 if comment.strip().startswith('set of param :'): 381 all_var = list(re.findall(r'''[^-]1\*(\w*)\b''', comment)) 382 # just the variable name as comment 383 elif len(comment.split()) == 1: 384 all_var = [comment.strip().lower()] 385 # either contraction or not formatted 386 else: 387 split = comment.split() 388 if len(split) >2 and split[1] == ':': 389 # NO VAR associated 390 restricted_value[(bname, lha_id)] = ' '.join(split[1:]) 391 elif len(split) == 2: 392 if re.search(r'''\[[A-Z]\]eV\^''', split[1]): 393 all_var = [comment.strip().lower()] 394 elif len(split) >=2 and split[1].startswith('('): 395 all_var = [split[0].strip().lower()] 396 else: 397 if not bname.startswith('qnumbers'): 398 logger.debug("not recognize information for %s %s : %s", 399 bname, lha_id, comment) 400 # not recognized format 401 continue 402 403 for var in all_var: 404 var = var.lower() 405 if var in pname2block: 406 pname2block[var].append((bname, lha_id)) 407 else: 408 pname2block[var] = [(bname, lha_id)] 409 410 return pname2block, restricted_value
411
412 - def write(self, outpath=None):
413 """schedular for writing a card""" 414 415 # order the block in a smart way 416 blocks = self.order_block() 417 text = self.header 418 text += ''.join([str(block) for block in blocks]) 419 420 if not outpath: 421 return text 422 elif isinstance(outpath, str): 423 file(outpath,'w').write(text) 424 else: 425 outpath.write(text) # for test purpose
426
427 - def create_diff(self, new_card):
428 """return a text file allowing to pass from this card to the new one 429 via the set command""" 430 431 diff = '' 432 for blockname, block in self.items(): 433 for param in block: 434 lhacode = param.lhacode 435 value = param.value 436 new_value = new_card[blockname].get(lhacode).value 437 if not misc.equal(value, new_value, 6, zero_limit=False): 438 lhacode = ' '.join([str(i) for i in lhacode]) 439 diff += 'set param_card %s %s %s # orig: %s\n' % \ 440 (blockname, lhacode , new_value, value) 441 return diff
442 443
444 - def write_inc_file(self, outpath, identpath, default, need_mp=False):
445 """ write a fortran file which hardcode the param value""" 446 447 fout = file_writers.FortranWriter(outpath) 448 defaultcard = ParamCard(default) 449 for line in open(identpath): 450 if line.startswith('c ') or line.startswith('ccccc'): 451 continue 452 split = line.split() 453 if len(split) < 3: 454 continue 455 block = split[0] 456 lhaid = [int(i) for i in split[1:-1]] 457 variable = split[-1] 458 if block in self: 459 try: 460 value = self[block].get(tuple(lhaid)).value 461 except KeyError: 462 value =defaultcard[block].get(tuple(lhaid)).value 463 logger.warning('information about \"%s %s" is missing using default value: %s.' %\ 464 (block, lhaid, value)) 465 else: 466 value =defaultcard[block].get(tuple(lhaid)).value 467 logger.warning('information about \"%s %s" is missing (full block missing) using default value: %s.' %\ 468 (block, lhaid, value)) 469 value = str(value).lower() 470 fout.writelines(' %s = %s' % (variable, ('%e'%float(value)).replace('e','d'))) 471 if need_mp: 472 fout.writelines(' mp__%s = %s_16' % (variable, value))
473
475 """ Convert this param_card to the convention used for the complex mass scheme: 476 This includes, removing the Yukawa block if present and making sure the EW input 477 scheme is (MZ, MW, aewm1). """ 478 479 # The yukawa block is irrelevant for the CMS models, we must remove them 480 if self.has_block('yukawa'): 481 # Notice that the last parameter removed will also remove the block. 482 for lhacode in [param.lhacode for param in self['yukawa']]: 483 self.remove_param('yukawa', lhacode) 484 485 # Now fix the EW input scheme 486 EW_input = {('sminputs',(1,)):None, 487 ('sminputs',(2,)):None, 488 ('mass',(23,)):None, 489 ('mass',(24,)):None} 490 for block, lhaid in EW_input.keys(): 491 try: 492 EW_input[(block,lhaid)] = self[block].get(lhaid).value 493 except: 494 pass 495 496 # Now specify the missing values. We only support the following EW 497 # input scheme: 498 # (alpha, GF, MZ) input 499 internal_param = [key for key,value in EW_input.items() if value is None] 500 if len(internal_param)==0: 501 # All parameters are already set, no need for modifications 502 return 503 504 if len(internal_param)!=1: 505 raise InvalidParamCard,' The specified EW inputs has more than one'+\ 506 ' unknown: [%s]'%(','.join([str(elem) for elem in internal_param])) 507 508 509 if not internal_param[0] in [('mass',(24,)), ('sminputs',(2,)), 510 ('sminputs',(1,))]: 511 raise InvalidParamCard, ' The only EW input scheme currently supported'+\ 512 ' are those with either the W mass or GF left internal.' 513 514 # Now if the Wmass is internal, then we must change the scheme 515 if internal_param[0] == ('mass',(24,)): 516 aewm1 = EW_input[('sminputs',(1,))] 517 Gf = EW_input[('sminputs',(2,))] 518 Mz = EW_input[('mass',(23,))] 519 try: 520 Mw = math.sqrt((Mz**2/2.0)+math.sqrt((Mz**4/4.0)-(( 521 (1.0/aewm1)*math.pi*Mz**2)/(Gf*math.sqrt(2.0))))) 522 except: 523 InvalidParamCard, 'The EW inputs 1/a_ew=%f, Gf=%f, Mz=%f are inconsistent'%\ 524 (aewm1,Gf,Mz) 525 self.remove_param('sminputs', (2,)) 526 self.add_param('mass', (24,), Mw, 'MW')
527
528 - def append(self, obj):
529 """add an object to this""" 530 531 assert isinstance(obj, Block) 532 self[obj.name] = obj 533 if not obj.name.startswith('decay_table'): 534 self.order.append(obj)
535 536 537
538 - def has_block(self, name):
539 return self.has_key(name)
540
541 - def order_block(self):
542 """ reorganize the block """ 543 return self.order
544
545 - def rename_blocks(self, name_dict):
546 """ rename the blocks """ 547 548 for old_name, new_name in name_dict.items(): 549 self[new_name] = self.pop(old_name) 550 self[new_name].name = new_name 551 for param in self[new_name]: 552 param.lhablock = new_name
553
554 - def remove_block(self, name):
555 """ remove a blocks """ 556 assert len(self[name])==0 557 [self.order.pop(i) for i,b in enumerate(self.order) if b.name == name] 558 self.pop(name)
559
560 - def remove_param(self, block, lhacode):
561 """ remove a parameter """ 562 if self.has_param(block, lhacode): 563 self[block].remove(lhacode) 564 if len(self[block]) == 0: 565 self.remove_block(block)
566
567 - def has_param(self, block, lhacode):
568 """check if param exists""" 569 570 try: 571 self[block].get(lhacode) 572 except: 573 return False 574 else: 575 return True
576
577 - def copy_param(self,old_block, old_lha, block=None, lhacode=None):
578 """ make a parameter, a symbolic link on another one """ 579 580 # Find the current block/parameter 581 old_block_obj = self[old_block] 582 parameter = old_block_obj.get(old_lha) 583 if not block: 584 block = old_block 585 if not lhacode: 586 lhacode = old_lha 587 588 self.add_param(block, lhacode, parameter.value, parameter.comment)
589
590 - def add_param(self,block, lha, value, comment=''):
591 592 parameter = Parameter(block=block, lhacode=lha, value=value, 593 comment=comment) 594 try: 595 new_block = self[block] 596 except KeyError: 597 # If the new block didn't exist yet 598 new_block = Block(block) 599 self.append(new_block) 600 new_block.append(parameter)
601 602
603 - def mod_param(self, old_block, old_lha, block=None, lhacode=None, 604 value=None, comment=None):
605 """ change a parameter to a new one. This is not a duplication.""" 606 607 # Find the current block/parameter 608 old_block = self[old_block] 609 try: 610 parameter = old_block.get(old_lha) 611 except: 612 if lhacode is not None: 613 lhacode=old_lha 614 self.add_param(block, lhacode, value, comment) 615 return 616 617 618 # Update the parameter 619 if block: 620 parameter.lhablock = block 621 if lhacode: 622 parameter.lhacode = lhacode 623 if value: 624 parameter.value = value 625 if comment: 626 parameter.comment = comment 627 628 # Change the block of the parameter 629 if block: 630 old_block.remove(old_lha) 631 if not len(old_block): 632 self.remove_block(old_block.name) 633 try: 634 new_block = self[block] 635 except KeyError: 636 # If the new block didn't exist yet 637 new_block = Block(block) 638 self.append(new_block) 639 new_block.append(parameter) 640 elif lhacode: 641 old_block.param_dict[tuple(lhacode)] = \ 642 old_block.param_dict.pop(tuple(old_lha))
643 644
645 - def check_and_remove(self, block, lhacode, value):
646 """ check that the value is coherent and remove it""" 647 648 if self.has_param(block, lhacode): 649 param = self[block].get(lhacode) 650 if param.value != value: 651 error_msg = 'This card is not suitable to be convert to SLAH1\n' 652 error_msg += 'Parameter %s %s should be %s' % (block, lhacode, value) 653 raise InvalidParamCard, error_msg 654 self.remove_param(block, lhacode)
655
656 657 -class ParamCardMP(ParamCard):
658 """ a param Card: list of Block with also MP definition of variables""" 659
660 - def write_inc_file(self, outpath, identpath, default):
661 """ write a fortran file which hardcode the param value""" 662 663 fout = file_writers.FortranWriter(outpath) 664 defaultcard = ParamCard(default) 665 for line in open(identpath): 666 if line.startswith('c ') or line.startswith('ccccc'): 667 continue 668 split = line.split() 669 if len(split) < 3: 670 continue 671 block = split[0] 672 lhaid = [int(i) for i in split[1:-1]] 673 variable = split[-1] 674 if block in self: 675 try: 676 value = self[block].get(tuple(lhaid)).value 677 except KeyError: 678 value =defaultcard[block].get(tuple(lhaid)).value 679 else: 680 value =defaultcard[block].get(tuple(lhaid)).value 681 #value = str(value).lower() 682 fout.writelines(' %s = %s' % (variable, ('%e' % value).replace('e','d'))) 683 fout.writelines(' %s%s = %s_16' % (self.mp_prefix, 684 variable, ('%e' % value)))
685
686 687 688 -class ParamCardIterator(ParamCard):
689 """A class keeping track of the scan: flag in the param_card and 690 having an __iter__() function to scan over all the points of the scan. 691 """ 692 693 logging = True
694 - def __init__(self, input_path=None):
695 super(ParamCardIterator, self).__init__(input_path=input_path) 696 self.itertag = [] #all the current value use 697 self.cross = [] # keep track of all the cross-section computed 698 self.param_order = []
699
700 - def __iter__(self):
701 """generate the next param_card (in a abstract way) related to the scan. 702 Technically this generates only the generator.""" 703 704 if hasattr(self, 'iterator'): 705 return self.iterator 706 self.iterator = self.iterate() 707 return self.iterator
708
709 - def next(self, autostart=False):
710 """call the next iteration value""" 711 try: 712 iterator = self.iterator 713 except: 714 if autostart: 715 iterator = self.__iter__() 716 else: 717 raise 718 try: 719 out = iterator.next() 720 except StopIteration: 721 del self.iterator 722 raise 723 return out
724
725 - def iterate(self):
726 """create the actual generator""" 727 all_iterators = {} # dictionary of key -> block of object to scan [([param, [values]), ...] 728 auto = 'Auto' 729 pattern = re.compile(r'''scan\s*(?P<id>\d*)\s*:\s*(?P<value>[^#]*)''', re.I) 730 # First determine which parameter to change and in which group 731 # so far only explicit value of the scan (no lambda function are allowed) 732 for block in self.order: 733 for param in block: 734 if isinstance(param.value, str) and param.value.strip().lower().startswith('scan'): 735 try: 736 key, def_list = pattern.findall(param.value)[0] 737 except: 738 raise Exception, "Fail to handle scanning tag: Please check that the syntax is valid" 739 if key == '': 740 key = -1 * len(all_iterators) 741 if key not in all_iterators: 742 all_iterators[key] = [] 743 try: 744 all_iterators[key].append( (param, eval(def_list))) 745 except SyntaxError, error: 746 raise Exception, "Fail to handle your scan definition. Please check your syntax:\n entry: %s \n Error reported: %s" %(def_list, error) 747 748 keys = all_iterators.keys() # need to fix an order for the scan 749 param_card = ParamCard(self) 750 #store the type of parameter 751 for key in keys: 752 for param, values in all_iterators[key]: 753 self.param_order.append("%s#%s" % (param.lhablock, '_'.join(`i` for i in param.lhacode))) 754 755 # do the loop 756 lengths = [range(len(all_iterators[key][0][1])) for key in keys] 757 for positions in itertools.product(*lengths): 758 self.itertag = [] 759 if self.logging: 760 logger.info("Create the next param_card in the scan definition", '$MG:color:BLACK') 761 for i, pos in enumerate(positions): 762 key = keys[i] 763 for param, values in all_iterators[key]: 764 # assign the value in the card. 765 param_card[param.lhablock].get(param.lhacode).value = values[pos] 766 self.itertag.append(values[pos]) 767 if self.logging: 768 logger.info("change parameter %s with code %s to %s", \ 769 param.lhablock, param.lhacode, values[pos]) 770 # retrun the current param_card up to next iteration 771 yield param_card
772 773
774 - def store_entry(self, run_name, cross):
775 """store the value of the cross-section""" 776 self.cross.append({'bench' : self.itertag, 'run_name': run_name, 'cross':cross})
777 778
779 - def write_summary(self, path):
780 """ """ 781 782 ff = open(path, 'w') 783 ff.write("#%-19s %-20s %-20s\n" % ('run_name',' '.join(self.param_order), 'cross(pb)')) 784 for info in self.cross: 785 bench = [str(p) for p in info['bench']] 786 cross = info['cross'] 787 name = info['run_name'] 788 ff.write("%-20s %-20s %-20s \n" % (name,' '.join(bench) ,cross))
789 #ff.write("%s %s %s \n" % (name,' '.join(bench) ,cross)) 790
791 - def get_next_name(self, run_name):
792 """returns a smart name for the next run""" 793 794 if '_' in run_name: 795 name, value = run_name.rsplit('_',1) 796 if value.isdigit(): 797 return '%s_%02i' % (name, float(value)+1) 798 # no valid '_' in the name 799 return '%s_scan_02' % run_name
800
801 802 -class ParamCardRule(object):
803 """ A class for storing the linked between the different parameter of 804 the param_card. 805 Able to write a file 'param_card_rule.dat' 806 Able to read a file 'param_card_rule.dat' 807 Able to check the validity of a param_card.dat 808 """ 809 810
811 - def __init__(self, inputpath=None):
812 """initialize an object """ 813 814 # constraint due to model restriction 815 self.zero = [] 816 self.one = [] 817 self.identical = [] 818 self.opposite = [] 819 820 # constraint due to the model 821 self.rule = [] 822 823 if inputpath: 824 self.load_rule(inputpath)
825
826 - def add_zero(self, lhablock, lhacode, comment=''):
827 """add a zero rule""" 828 self.zero.append( (lhablock, lhacode, comment) )
829
830 - def add_one(self, lhablock, lhacode, comment=''):
831 """add a one rule""" 832 self.one.append( (lhablock, lhacode, comment) )
833
834 - def add_identical(self, lhablock, lhacode, lhacode2, comment=''):
835 """add a rule for identical value""" 836 self.identical.append( (lhablock, lhacode, lhacode2, comment) )
837
838 - def add_opposite(self, lhablock, lhacode, lhacode2, comment=''):
839 """add a rule for identical value""" 840 self.opposite.append( (lhablock, lhacode, lhacode2, comment) )
841 842
843 - def add_rule(self, lhablock, lhacode, rule, comment=''):
844 """add a rule for constraint value""" 845 self.rule.append( (lhablock, lhacode, rule) )
846
847 - def write_file(self, output=None):
848 849 text = """<file>###################################################################### 850 ## VALIDITY RULE FOR THE PARAM_CARD #### 851 ######################################################################\n""" 852 853 # ZERO 854 text +='<zero>\n' 855 for name, id, comment in self.zero: 856 text+=' %s %s # %s\n' % (name, ' '.join([str(i) for i in id]), 857 comment) 858 # ONE 859 text +='</zero>\n<one>\n' 860 for name, id, comment in self.one: 861 text+=' %s %s # %s\n' % (name, ' '.join([str(i) for i in id]), 862 comment) 863 # IDENTICAL 864 text +='</one>\n<identical>\n' 865 for name, id,id2, comment in self.identical: 866 text+=' %s %s : %s # %s\n' % (name, ' '.join([str(i) for i in id]), 867 ' '.join([str(i) for i in id2]), comment) 868 869 # OPPOSITE 870 text +='</identical>\n<opposite>\n' 871 for name, id,id2, comment in self.opposite: 872 text+=' %s %s : %s # %s\n' % (name, ' '.join([str(i) for i in id]), 873 ' '.join([str(i) for i in id2]), comment) 874 875 # CONSTRAINT 876 text += '</opposite>\n<constraint>\n' 877 for name, id, rule, comment in self.rule: 878 text += ' %s %s : %s # %s\n' % (name, ' '.join([str(i) for i in id]), 879 rule, comment) 880 text += '</constraint>\n</file>' 881 882 if isinstance(output, str): 883 output = open(output,'w') 884 if hasattr(output, 'write'): 885 output.write(text) 886 return text
887
888 - def load_rule(self, inputpath):
889 """ import a validity rule file """ 890 891 892 try: 893 tree = ET.parse(inputpath) 894 except IOError: 895 if '\n' in inputpath: 896 # this is convinient for the tests 897 tree = ET.fromstring(inputpath) 898 else: 899 raise 900 901 #Add zero element 902 element = tree.find('zero') 903 if element is not None: 904 for line in element.text.split('\n'): 905 line = line.split('#',1)[0] 906 if not line: 907 continue 908 lhacode = line.split() 909 blockname = lhacode.pop(0) 910 lhacode = [int(code) for code in lhacode ] 911 self.add_zero(blockname, lhacode, '') 912 913 #Add one element 914 element = tree.find('one') 915 if element is not None: 916 for line in element.text.split('\n'): 917 line = line.split('#',1)[0] 918 if not line: 919 continue 920 lhacode = line.split() 921 blockname = lhacode.pop(0) 922 lhacode = [int(code) for code in lhacode ] 923 self.add_one(blockname, lhacode, '') 924 925 #Add Identical element 926 element = tree.find('identical') 927 if element is not None: 928 for line in element.text.split('\n'): 929 line = line.split('#',1)[0] 930 if not line: 931 continue 932 line, lhacode2 = line.split(':') 933 lhacode = line.split() 934 blockname = lhacode.pop(0) 935 lhacode = [int(code) for code in lhacode ] 936 lhacode2 = [int(code) for code in lhacode2.split() ] 937 self.add_identical(blockname, lhacode, lhacode2, '') 938 939 #Add Opposite element 940 element = tree.find('opposite') 941 if element is not None: 942 for line in element.text.split('\n'): 943 line = line.split('#',1)[0] 944 if not line: 945 continue 946 line, lhacode2 = line.split(':') 947 lhacode = line.split() 948 blockname = lhacode.pop(0) 949 lhacode = [int(code) for code in lhacode ] 950 lhacode2 = [int(code) for code in lhacode2.split() ] 951 self.add_opposite(blockname, lhacode, lhacode2, '') 952 953 #Add Rule element 954 element = tree.find('rule') 955 if element is not None: 956 for line in element.text.split('\n'): 957 line = line.split('#',1)[0] 958 if not line: 959 continue 960 line, rule = line.split(':') 961 lhacode = line.split() 962 blockname = lhacode.pop(0) 963 self.add_rule(blockname, lhacode, rule, '')
964 965 @staticmethod
966 - def read_param_card(path):
967 """ read a param_card and return a dictionary with the associated value.""" 968 969 output = ParamCard(path) 970 971 972 973 return output
974 975 @staticmethod
976 - def write_param_card(path, data):
977 """ read a param_card and return a dictionary with the associated value.""" 978 979 output = {} 980 981 if isinstance(path, str): 982 output = open(path, 'w') 983 else: 984 output = path # helpfull for the test 985 986 data.write(path)
987 988
989 - def check_param_card(self, path, modify=False):
990 """Check that the restriction card are applied""" 991 992 card = self.read_param_card(path) 993 994 # check zero 995 for block, id, comment in self.zero: 996 try: 997 value = float(card[block].get(id).value) 998 except KeyError: 999 if modify: 1000 new_param = Parameter(block=block,lhacode=id, value=0, 1001 comment='fixed by the model') 1002 if block in card: 1003 card[block].append(new_param) 1004 else: 1005 new_block = Block(block) 1006 card.append(new_block) 1007 new_block.append(new_param) 1008 else: 1009 if value != 0: 1010 if not modify: 1011 raise InvalidParamCard, 'parameter %s: %s is not at zero' % \ 1012 (block, ' '.join([str(i) for i in id])) 1013 else: 1014 param = card[block].get(id) 1015 param.value = 0.0 1016 param.comment += ' fixed by the model' 1017 1018 # check one 1019 for block, id, comment in self.one: 1020 try: 1021 value = card[block].get(id).value 1022 except KeyError: 1023 if modify: 1024 new_param = Parameter(block=block,lhacode=id, value=1, 1025 comment='fixed by the model') 1026 if block in card: 1027 card[block].append(new_param) 1028 else: 1029 new_block = Block(block) 1030 card.append(new_block) 1031 new_block.append(new_param) 1032 else: 1033 if value != 1: 1034 if not modify: 1035 raise InvalidParamCard, 'parameter %s: %s is not at one but at %s' % \ 1036 (block, ' '.join([str(i) for i in id]), value) 1037 else: 1038 param = card[block].get(id) 1039 param.value = 1.0 1040 param.comment += ' fixed by the model' 1041 1042 1043 # check identical 1044 for block, id1, id2, comment in self.identical: 1045 if block not in card: 1046 logger.warning('''Param card is not complete: Block %s is simply missing. 1047 We will use model default for all missing value! Please cross-check that 1048 this correspond to your expectation.''' % block) 1049 continue 1050 value2 = float(card[block].get(id2).value) 1051 try: 1052 param = card[block].get(id1) 1053 except KeyError: 1054 if modify: 1055 new_param = Parameter(block=block,lhacode=id1, value=value2, 1056 comment='must be identical to %s' %id2) 1057 card[block].append(new_param) 1058 else: 1059 value1 = float(param.value) 1060 1061 if value1 != value2: 1062 if not modify: 1063 raise InvalidParamCard, 'parameter %s: %s is not to identical to parameter %s' % \ 1064 (block, ' '.join([str(i) for i in id1]), 1065 ' '.join([str(i) for i in id2])) 1066 else: 1067 param = card[block].get(id1) 1068 param.value = value2 1069 param.comment += ' must be identical to %s' % id2 1070 1071 # check opposite 1072 for block, id1, id2, comment in self.opposite: 1073 value2 = float(card[block].get(id2).value) 1074 try: 1075 param = card[block].get(id1) 1076 except KeyError: 1077 if modify: 1078 new_param = Parameter(block=block,lhacode=id1, value=-value2, 1079 comment='must be opposite to to %s' %id2) 1080 card[block].append(new_param) 1081 else: 1082 value1 = float(param.value) 1083 1084 if value1 != -value2: 1085 if not modify: 1086 raise InvalidParamCard, 'parameter %s: %s is not to opposite to parameter %s' % \ 1087 (block, ' '.join([str(i) for i in id1]), 1088 ' '.join([str(i) for i in id2])) 1089 else: 1090 param = card[block].get(id1) 1091 param.value = -value2 1092 param.comment += ' must be opposite to %s' % id2 1093 1094 return card
1095
1096 1097 -def convert_to_slha1(path, outputpath=None ):
1098 """ """ 1099 1100 if not outputpath: 1101 outputpath = path 1102 card = ParamCard(path) 1103 if not 'usqmix' in card: 1104 #already slha1 1105 card.write(outputpath) 1106 return 1107 1108 # Mass 1109 #card.reorder_mass() # needed? 1110 card.copy_param('mass', [6], 'sminputs', [6]) 1111 card.copy_param('mass', [15], 'sminputs', [7]) 1112 card.copy_param('mass', [23], 'sminputs', [4]) 1113 # Decay: Nothing to do. 1114 1115 # MODSEL 1116 card.add_param('modsel',[1], value=1) 1117 card['modsel'].get([1]).format = 'int' 1118 1119 # find scale 1120 scale = card['hmix'].scale 1121 if not scale: 1122 scale = 1 # Need to be define (this is dummy value) 1123 1124 # SMINPUTS 1125 if not card.has_param('sminputs', [2]): 1126 aem1 = card['sminputs'].get([1]).value 1127 mz = card['mass'].get([23]).value 1128 mw = card['mass'].get([24]).value 1129 gf = math.pi / math.sqrt(2) / aem1 * mz**2/ mw**2 /(mz**2-mw**2) 1130 card.add_param('sminputs', [2], gf, 'G_F [GeV^-2]') 1131 1132 # USQMIX 1133 card.check_and_remove('usqmix', [1,1], 1.0) 1134 card.check_and_remove('usqmix', [2,2], 1.0) 1135 card.check_and_remove('usqmix', [4,4], 1.0) 1136 card.check_and_remove('usqmix', [5,5], 1.0) 1137 card.mod_param('usqmix', [3,3], 'stopmix', [1,1]) 1138 card.mod_param('usqmix', [3,6], 'stopmix', [1,2]) 1139 card.mod_param('usqmix', [6,3], 'stopmix', [2,1]) 1140 card.mod_param('usqmix', [6,6], 'stopmix', [2,2]) 1141 1142 # DSQMIX 1143 card.check_and_remove('dsqmix', [1,1], 1.0) 1144 card.check_and_remove('dsqmix', [2,2], 1.0) 1145 card.check_and_remove('dsqmix', [4,4], 1.0) 1146 card.check_and_remove('dsqmix', [5,5], 1.0) 1147 card.mod_param('dsqmix', [3,3], 'sbotmix', [1,1]) 1148 card.mod_param('dsqmix', [3,6], 'sbotmix', [1,2]) 1149 card.mod_param('dsqmix', [6,3], 'sbotmix', [2,1]) 1150 card.mod_param('dsqmix', [6,6], 'sbotmix', [2,2]) 1151 1152 1153 # SELMIX 1154 card.check_and_remove('selmix', [1,1], 1.0) 1155 card.check_and_remove('selmix', [2,2], 1.0) 1156 card.check_and_remove('selmix', [4,4], 1.0) 1157 card.check_and_remove('selmix', [5,5], 1.0) 1158 card.mod_param('selmix', [3,3], 'staumix', [1,1]) 1159 card.mod_param('selmix', [3,6], 'staumix', [1,2]) 1160 card.mod_param('selmix', [6,3], 'staumix', [2,1]) 1161 card.mod_param('selmix', [6,6], 'staumix', [2,2]) 1162 1163 # FRALPHA 1164 card.mod_param('fralpha', [1], 'alpha', [' ']) 1165 1166 #HMIX 1167 if not card.has_param('hmix', [3]): 1168 aem1 = card['sminputs'].get([1]).value 1169 tanb = card['hmix'].get([2]).value 1170 mz = card['mass'].get([23]).value 1171 mw = card['mass'].get([24]).value 1172 sw = math.sqrt(mz**2 - mw**2)/mz 1173 ee = 2 * math.sqrt(1/aem1) * math.sqrt(math.pi) 1174 vu = 2 * mw *sw /ee * math.sin(math.atan(tanb)) 1175 card.add_param('hmix', [3], vu, 'higgs vev(Q) MSSM DRb') 1176 card['hmix'].scale= scale 1177 1178 # VCKM 1179 card.check_and_remove('vckm', [1,1], 1.0) 1180 card.check_and_remove('vckm', [2,2], 1.0) 1181 card.check_and_remove('vckm', [3,3], 1.0) 1182 1183 #SNUMIX 1184 card.check_and_remove('snumix', [1,1], 1.0) 1185 card.check_and_remove('snumix', [2,2], 1.0) 1186 card.check_and_remove('snumix', [3,3], 1.0) 1187 1188 #UPMNS 1189 card.check_and_remove('upmns', [1,1], 1.0) 1190 card.check_and_remove('upmns', [2,2], 1.0) 1191 card.check_and_remove('upmns', [3,3], 1.0) 1192 1193 # Te 1194 ye = card['ye'].get([3, 3]).value 1195 te = card['te'].get([3, 3]).value 1196 card.mod_param('te', [3,3], 'ae', [3,3], value= te/ye, comment='A_tau(Q) DRbar') 1197 card.add_param('ae', [1,1], 0, 'A_e(Q) DRbar') 1198 card.add_param('ae', [2,2], 0, 'A_mu(Q) DRbar') 1199 card['ae'].scale = scale 1200 card['ye'].scale = scale 1201 1202 # Tu 1203 yu = card['yu'].get([3, 3]).value 1204 tu = card['tu'].get([3, 3]).value 1205 card.mod_param('tu', [3,3], 'au', [3,3], value= tu/yu, comment='A_t(Q) DRbar') 1206 card.add_param('au', [1,1], 0, 'A_u(Q) DRbar') 1207 card.add_param('au', [2,2], 0, 'A_c(Q) DRbar') 1208 card['au'].scale = scale 1209 card['yu'].scale = scale 1210 1211 # Td 1212 yd = card['yd'].get([3, 3]).value 1213 td = card['td'].get([3, 3]).value 1214 if td: 1215 card.mod_param('td', [3,3], 'ad', [3,3], value= td/yd, comment='A_b(Q) DRbar') 1216 else: 1217 card.mod_param('td', [3,3], 'ad', [3,3], value= 0., comment='A_b(Q) DRbar') 1218 card.add_param('ad', [1,1], 0, 'A_d(Q) DRbar') 1219 card.add_param('ad', [2,2], 0, 'A_s(Q) DRbar') 1220 card['ad'].scale = scale 1221 card['yd'].scale = scale 1222 1223 # MSL2 1224 value = card['msl2'].get([1, 1]).value 1225 card.mod_param('msl2', [1,1], 'msoft', [31], math.sqrt(value)) 1226 value = card['msl2'].get([2, 2]).value 1227 card.mod_param('msl2', [2,2], 'msoft', [32], math.sqrt(value)) 1228 value = card['msl2'].get([3, 3]).value 1229 card.mod_param('msl2', [3,3], 'msoft', [33], math.sqrt(value)) 1230 card['msoft'].scale = scale 1231 1232 # MSE2 1233 value = card['mse2'].get([1, 1]).value 1234 card.mod_param('mse2', [1,1], 'msoft', [34], math.sqrt(value)) 1235 value = card['mse2'].get([2, 2]).value 1236 card.mod_param('mse2', [2,2], 'msoft', [35], math.sqrt(value)) 1237 value = card['mse2'].get([3, 3]).value 1238 card.mod_param('mse2', [3,3], 'msoft', [36], math.sqrt(value)) 1239 1240 # MSQ2 1241 value = card['msq2'].get([1, 1]).value 1242 card.mod_param('msq2', [1,1], 'msoft', [41], math.sqrt(value)) 1243 value = card['msq2'].get([2, 2]).value 1244 card.mod_param('msq2', [2,2], 'msoft', [42], math.sqrt(value)) 1245 value = card['msq2'].get([3, 3]).value 1246 card.mod_param('msq2', [3,3], 'msoft', [43], math.sqrt(value)) 1247 1248 # MSU2 1249 value = card['msu2'].get([1, 1]).value 1250 card.mod_param('msu2', [1,1], 'msoft', [44], math.sqrt(value)) 1251 value = card['msu2'].get([2, 2]).value 1252 card.mod_param('msu2', [2,2], 'msoft', [45], math.sqrt(value)) 1253 value = card['msu2'].get([3, 3]).value 1254 card.mod_param('msu2', [3,3], 'msoft', [46], math.sqrt(value)) 1255 1256 # MSD2 1257 value = card['msd2'].get([1, 1]).value 1258 card.mod_param('msd2', [1,1], 'msoft', [47], math.sqrt(value)) 1259 value = card['msd2'].get([2, 2]).value 1260 card.mod_param('msd2', [2,2], 'msoft', [48], math.sqrt(value)) 1261 value = card['msd2'].get([3, 3]).value 1262 card.mod_param('msd2', [3,3], 'msoft', [49], math.sqrt(value)) 1263 1264 1265 1266 ################# 1267 # WRITE OUTPUT 1268 ################# 1269 card.write(outputpath)
1270
1271 1272 1273 -def convert_to_mg5card(path, outputpath=None, writting=True):
1274 """ 1275 """ 1276 1277 if not outputpath: 1278 outputpath = path 1279 card = ParamCard(path) 1280 if 'usqmix' in card: 1281 #already mg5(slha2) format 1282 if outputpath != path and writting: 1283 card.write(outputpath) 1284 return card 1285 1286 1287 # SMINPUTS 1288 card.remove_param('sminputs', [2]) 1289 card.remove_param('sminputs', [4]) 1290 card.remove_param('sminputs', [6]) 1291 card.remove_param('sminputs', [7]) 1292 # Decay: Nothing to do. 1293 1294 # MODSEL 1295 card.remove_param('modsel',[1]) 1296 1297 1298 # USQMIX 1299 card.add_param('usqmix', [1,1], 1.0) 1300 card.add_param('usqmix', [2,2], 1.0) 1301 card.add_param('usqmix', [4,4], 1.0) 1302 card.add_param('usqmix', [5,5], 1.0) 1303 card.mod_param('stopmix', [1,1], 'usqmix', [3,3]) 1304 card.mod_param('stopmix', [1,2], 'usqmix', [3,6]) 1305 card.mod_param('stopmix', [2,1], 'usqmix', [6,3]) 1306 card.mod_param('stopmix', [2,2], 'usqmix', [6,6]) 1307 1308 # DSQMIX 1309 card.add_param('dsqmix', [1,1], 1.0) 1310 card.add_param('dsqmix', [2,2], 1.0) 1311 card.add_param('dsqmix', [4,4], 1.0) 1312 card.add_param('dsqmix', [5,5], 1.0) 1313 card.mod_param('sbotmix', [1,1], 'dsqmix', [3,3]) 1314 card.mod_param('sbotmix', [1,2], 'dsqmix', [3,6]) 1315 card.mod_param('sbotmix', [2,1], 'dsqmix', [6,3]) 1316 card.mod_param('sbotmix', [2,2], 'dsqmix', [6,6]) 1317 1318 1319 # SELMIX 1320 card.add_param('selmix', [1,1], 1.0) 1321 card.add_param('selmix', [2,2], 1.0) 1322 card.add_param('selmix', [4,4], 1.0) 1323 card.add_param('selmix', [5,5], 1.0) 1324 card.mod_param('staumix', [1,1], 'selmix', [3,3]) 1325 card.mod_param('staumix', [1,2], 'selmix', [3,6]) 1326 card.mod_param('staumix', [2,1], 'selmix', [6,3]) 1327 card.mod_param('staumix', [2,2], 'selmix', [6,6]) 1328 1329 # FRALPHA 1330 card.mod_param('alpha', [], 'fralpha', [1]) 1331 1332 #HMIX 1333 card.remove_param('hmix', [3]) 1334 1335 # VCKM 1336 card.add_param('vckm', [1,1], 1.0) 1337 card.add_param('vckm', [2,2], 1.0) 1338 card.add_param('vckm', [3,3], 1.0) 1339 1340 #SNUMIX 1341 card.add_param('snumix', [1,1], 1.0) 1342 card.add_param('snumix', [2,2], 1.0) 1343 card.add_param('snumix', [3,3], 1.0) 1344 1345 #UPMNS 1346 card.add_param('upmns', [1,1], 1.0) 1347 card.add_param('upmns', [2,2], 1.0) 1348 card.add_param('upmns', [3,3], 1.0) 1349 1350 # Te 1351 ye = card['ye'].get([1, 1], default=0).value 1352 ae = card['ae'].get([1, 1], default=0).value 1353 card.mod_param('ae', [1,1], 'te', [1,1], value= ae * ye, comment='T_e(Q) DRbar') 1354 if ae * ye: 1355 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model 1356 Parameter ae [1, 1] times ye [1,1] should be 0''' 1357 card.remove_param('ae', [1,1]) 1358 #2 1359 ye = card['ye'].get([2, 2], default=0).value 1360 1361 ae = card['ae'].get([2, 2], default=0).value 1362 card.mod_param('ae', [2,2], 'te', [2,2], value= ae * ye, comment='T_mu(Q) DRbar') 1363 if ae * ye: 1364 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model 1365 Parameter ae [2, 2] times ye [2,2] should be 0''' 1366 card.remove_param('ae', [2,2]) 1367 #3 1368 ye = card['ye'].get([3, 3], default=0).value 1369 ae = card['ae'].get([3, 3], default=0).value 1370 card.mod_param('ae', [3,3], 'te', [3,3], value= ae * ye, comment='T_tau(Q) DRbar') 1371 1372 # Tu 1373 yu = card['yu'].get([1, 1], default=0).value 1374 au = card['au'].get([1, 1], default=0).value 1375 card.mod_param('au', [1,1], 'tu', [1,1], value= au * yu, comment='T_u(Q) DRbar') 1376 if au * yu: 1377 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model 1378 Parameter au [1, 1] times yu [1,1] should be 0''' 1379 card.remove_param('au', [1,1]) 1380 #2 1381 ye = card['yu'].get([2, 2], default=0).value 1382 1383 ae = card['au'].get([2, 2], default=0).value 1384 card.mod_param('au', [2,2], 'tu', [2,2], value= au * yu, comment='T_c(Q) DRbar') 1385 if au * yu: 1386 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model 1387 Parameter au [2, 2] times yu [2,2] should be 0''' 1388 card.remove_param('au', [2,2]) 1389 #3 1390 yu = card['yu'].get([3, 3]).value 1391 au = card['au'].get([3, 3]).value 1392 card.mod_param('au', [3,3], 'tu', [3,3], value= au * yu, comment='T_t(Q) DRbar') 1393 1394 # Td 1395 yd = card['yd'].get([1, 1], default=0).value 1396 ad = card['ad'].get([1, 1], default=0).value 1397 card.mod_param('ad', [1,1], 'td', [1,1], value= ad * yd, comment='T_d(Q) DRbar') 1398 if ad * yd: 1399 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model 1400 Parameter ad [1, 1] times yd [1,1] should be 0''' 1401 card.remove_param('ad', [1,1]) 1402 #2 1403 ye = card['yd'].get([2, 2], default=0).value 1404 1405 ae = card['ad'].get([2, 2], default=0).value 1406 card.mod_param('ad', [2,2], 'td', [2,2], value= ad * yd, comment='T_s(Q) DRbar') 1407 if ad * yd: 1408 raise InvalidParamCard, '''This card is not suitable to be converted to MSSM UFO model 1409 Parameter ad [2, 2] times yd [2,2] should be 0''' 1410 card.remove_param('ad', [2,2]) 1411 #3 1412 yd = card['yd'].get([3, 3]).value 1413 ad = card['ad'].get([3, 3]).value 1414 card.mod_param('ad', [3,3], 'td', [3,3], value= ad * yd, comment='T_b(Q) DRbar') 1415 1416 1417 # MSL2 1418 value = card['msoft'].get([31]).value 1419 card.mod_param('msoft', [31], 'msl2', [1,1], value**2) 1420 value = card['msoft'].get([32]).value 1421 card.mod_param('msoft', [32], 'msl2', [2,2], value**2) 1422 value = card['msoft'].get([33]).value 1423 card.mod_param('msoft', [33], 'msl2', [3,3], value**2) 1424 1425 # MSE2 1426 value = card['msoft'].get([34]).value 1427 card.mod_param('msoft', [34], 'mse2', [1,1], value**2) 1428 value = card['msoft'].get([35]).value 1429 card.mod_param('msoft', [35], 'mse2', [2,2], value**2) 1430 value = card['msoft'].get([36]).value 1431 card.mod_param('msoft', [36], 'mse2', [3,3], value**2) 1432 1433 # MSQ2 1434 value = card['msoft'].get([41]).value 1435 card.mod_param('msoft', [41], 'msq2', [1,1], value**2) 1436 value = card['msoft'].get([42]).value 1437 card.mod_param('msoft', [42], 'msq2', [2,2], value**2) 1438 value = card['msoft'].get([43]).value 1439 card.mod_param('msoft', [43], 'msq2', [3,3], value**2) 1440 1441 # MSU2 1442 value = card['msoft'].get([44]).value 1443 card.mod_param('msoft', [44], 'msu2', [1,1], value**2) 1444 value = card['msoft'].get([45]).value 1445 card.mod_param('msoft', [45], 'msu2', [2,2], value**2) 1446 value = card['msoft'].get([46]).value 1447 card.mod_param('msoft', [46], 'msu2', [3,3], value**2) 1448 1449 # MSD2 1450 value = card['msoft'].get([47]).value 1451 card.mod_param('msoft', [47], 'msd2', [1,1], value**2) 1452 value = card['msoft'].get([48]).value 1453 card.mod_param('msoft', [48], 'msd2', [2,2], value**2) 1454 value = card['msoft'].get([49]).value 1455 card.mod_param('msoft', [49], 'msd2', [3,3], value**2) 1456 1457 ################# 1458 # WRITE OUTPUT 1459 ################# 1460 if writting: 1461 card.write(outputpath) 1462 return card
1463
1464 1465 -def make_valid_param_card(path, restrictpath, outputpath=None):
1466 """ modify the current param_card such that it agrees with the restriction""" 1467 1468 if not outputpath: 1469 outputpath = path 1470 1471 cardrule = ParamCardRule() 1472 cardrule.load_rule(restrictpath) 1473 try : 1474 cardrule.check_param_card(path, modify=False) 1475 except InvalidParamCard: 1476 new_data = cardrule.check_param_card(path, modify=True) 1477 cardrule.write_param_card(outputpath, new_data) 1478 else: 1479 if path != outputpath: 1480 shutil.copy(path, outputpath) 1481 return cardrule
1482
1483 -def check_valid_param_card(path, restrictpath=None):
1484 """ check if the current param_card agrees with the restriction""" 1485 1486 if restrictpath is None: 1487 restrictpath = os.path.dirname(path) 1488 restrictpath = os.path.join(restrictpath, os.pardir, os.pardir, 'Source', 1489 'MODEL', 'param_card_rule.dat') 1490 if not os.path.exists(restrictpath): 1491 restrictpath = os.path.dirname(path) 1492 restrictpath = os.path.join(restrictpath, os.pardir, 'Source', 1493 'MODEL', 'param_card_rule.dat') 1494 if not os.path.exists(restrictpath): 1495 return True 1496 1497 cardrule = ParamCardRule() 1498 cardrule.load_rule(restrictpath) 1499 cardrule.check_param_card(path, modify=False)
1500 1501 if '__main__' == __name__: 1502 1503 1504 #make_valid_param_card('./Cards/param_card.dat', './Source/MODEL/param_card_rule.dat', 1505 # outputpath='tmp1.dat') 1506 import sys 1507 args = sys.argv 1508 sys.path.append(os.path.dirname(__file__)) 1509 convert_to_slha1(args[1] , args[2]) 1510