1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 """A File for splitting"""
16
17 import sys
18 import re
19 import os
20
21 pjoin = os.path.join
22
23 try:
24 import madgraph.various.misc as misc
25 import madgraph.iolibs.file_writers as file_writers
26 import madgraph.iolibs.files as files
27 import models.check_param_card as param_card_reader
28 from madgraph import MG5DIR, InvalidCmd
29 MADEVENT = False
30 except ImportError:
31 MADEVENT = True
32 import internal.file_writers as file_writers
33 import internal.files as files
34 import internal.check_param_card as param_card_reader
35 import internal.misc as misc
36 from internal import InvalidCmd
37
38 MEDIR = os.path.split(os.path.dirname(os.path.realpath( __file__ )))[0]
39 MEDIR = os.path.split(MEDIR)[0]
40
41 import logging
42
43 logger = logging.getLogger('madevent.cards')
47 """ """
48
49 ordered_items = ['mgversion', 'mg5proccard', 'mgproccard', 'mgruncard',
50 'slha', 'mggenerationinfo', 'mgpythiacard', 'mgpgscard',
51 'mgdelphescard', 'mgdelphestrigger','mgshowercard','run_settings']
52
53 capitalized_items = {
54 'mgversion': 'MGVersion',
55 'mg5proccard': 'MG5ProcCard',
56 'mgproccard': 'MGProcCard',
57 'mgruncard': 'MGRunCard',
58 'mggenerationinfo': 'MGGenerationInfo',
59 'mgpythiacard': 'MGPythiaCard',
60 'mgpgscard': 'MGPGSCard',
61 'mgdelphescard': 'MGDelphesCard',
62 'mgdelphestrigger': 'MGDelphesTrigger',
63 'mgshowercard': 'MGShowerCard' }
64
66 """ """
67 if isinstance(banner_path, Banner):
68 dict.__init__(self, banner_path)
69 self.lhe_version = banner_path.lhe_version
70 return
71 else:
72 dict.__init__(self)
73
74
75 if MADEVENT:
76 self['mgversion'] = '#%s\n' % open(pjoin(MEDIR, 'MGMEVersion.txt')).read()
77 else:
78 info = misc.get_pkg_info()
79 self['mgversion'] = info['version']+'\n'
80
81 self.lhe_version = None
82
83
84 if banner_path:
85 self.read_banner(banner_path)
86
87
88
89
90 pat_begin=re.compile('<(?P<name>\w*)>')
91 pat_end=re.compile('</(?P<name>\w*)>')
92
93 tag_to_file={'slha':'param_card.dat',
94 'mgruncard':'run_card.dat',
95 'mgpythiacard':'pythia_card.dat',
96 'mgpgscard' : 'pgs_card.dat',
97 'mgdelphescard':'delphes_card.dat',
98 'mgdelphestrigger':'delphes_trigger.dat',
99 'mg5proccard':'proc_card_mg5.dat',
100 'mgproccard': 'proc_card.dat',
101 'init': '',
102 'mggenerationinfo':'',
103 'scalesfunctionalform':'',
104 'montecarlomasses':'',
105 'initrwgt':'',
106 'madspin':'madspin_card.dat',
107 'mgshowercard':'shower_card.dat',
108 'run_settings':''
109 }
110
112 """read a banner"""
113
114 if isinstance(input_path, str):
115 input_path = open(input_path)
116
117 text = ''
118 store = False
119 for line in input_path:
120 if self.pat_begin.search(line):
121 tag = self.pat_begin.search(line).group('name').lower()
122 if tag in self.tag_to_file:
123 store = True
124 continue
125 if store and self.pat_end.search(line):
126 if tag == self.pat_end.search(line).group('name').lower():
127 self[tag] = text
128 text = ''
129 store = False
130 if store:
131 if line.endswith('\n'):
132 text += line
133 else:
134 text += '%s%s' % (line, '\n')
135
136
137 if "</init>" in line:
138 break
139 elif "<event>" in line:
140 break
141
143 """change the lhe version associate to the banner"""
144
145 version = float(version)
146 if version < 3:
147 version = 1
148 elif version > 3:
149 raise Exception, "Not Supported version"
150 self.lhe_version = version
151
153 """ Load the proc_card /param_card and run_card """
154
155 self.add(pjoin(medir,'Cards', 'param_card.dat'))
156 self.add(pjoin(medir,'Cards', 'run_card.dat'))
157 if os.path.exists(pjoin(medir, 'SubProcesses', 'procdef_mg5.dat')):
158 self.add(pjoin(medir,'SubProcesses', 'procdef_mg5.dat'))
159 self.add(pjoin(medir,'Cards', 'proc_card_mg5.dat'))
160 else:
161 self.add(pjoin(medir,'Cards', 'proc_card.dat'))
162
163
165 """Change the seed value in the banner"""
166
167 p = re.compile(r'''^\s*\d+\s*=\s*iseed''', re.M)
168 new_seed_str = " %s = iseed" % seed
169 self['mgruncard'] = p.sub(new_seed_str, self['mgruncard'])
170
172 """add info on MGGeneration"""
173
174 text = """
175 # Number of Events : %s
176 # Integrated weight (pb) : %s
177 """ % (nb_event, cross)
178 self['MGGenerationInfo'] = text
179
180
181
182
183 - def split(self, me_dir, proc_card=True):
184 """write the banner in the Cards directory.
185 proc_card argument is present to avoid the overwrite of proc_card
186 information"""
187
188 for tag, text in self.items():
189 if tag == 'mgversion':
190 continue
191 if not proc_card and tag in ['mg5proccard','mgproccard']:
192 continue
193 if not self.tag_to_file[tag]:
194 continue
195 ff = open(pjoin(me_dir, 'Cards', self.tag_to_file[tag]), 'w')
196 ff.write(text)
197 ff.close()
198
199
200
201
202
204 """special routine removing width/mass of particles not present in the model
205 This is usefull in case of loop model card, when we want to use the non
206 loop model."""
207
208 if not hasattr(self, 'param_card'):
209 self.charge_card('slha')
210
211 for tag in ['mass', 'decay']:
212 block = self.param_card.get(tag)
213 for data in block:
214 pid = data.lhacode[0]
215 if pid not in pid2label.keys():
216 block.remove((pid,))
217
218
219
220
221
222 - def write(self, output_path, close_tag=True, exclude=[]):
223 """write the banner"""
224
225 if isinstance(output_path, str):
226 ff = open(output_path, 'w')
227 else:
228 ff = output_path
229
230 if MADEVENT:
231 header = open(pjoin(MEDIR, 'Source', 'banner_header.txt')).read()
232 else:
233 header = open(pjoin(MG5DIR,'Template', 'LO', 'Source', 'banner_header.txt')).read()
234
235 if not self.lhe_version:
236 self.lhe_version = self.get('run_card', 'lhe_version', default=1.0)
237 if float(self.lhe_version) < 3:
238 self.lhe_version = 1.0
239
240 ff.write(header % { 'version':float(self.lhe_version)})
241
242
243 for tag in [t for t in self.ordered_items if t in self.keys()]:
244 if tag in exclude:
245 continue
246 capitalized_tag = self.capitalized_items[tag] if tag in self.capitalized_items else tag
247 ff.write('<%(tag)s>\n%(text)s\n</%(tag)s>\n' % \
248 {'tag':capitalized_tag, 'text':self[tag].strip()})
249 for tag in [t for t in self.keys() if t not in self.ordered_items]:
250 if tag in ['init'] or tag in exclude:
251 continue
252 capitalized_tag = self.capitalized_items[tag] if tag in self.capitalized_items else tag
253 ff.write('<%(tag)s>\n%(text)s\n</%(tag)s>\n' % \
254 {'tag':capitalized_tag, 'text':self[tag].strip()})
255
256 if not '/header' in exclude:
257 ff.write('</header>\n')
258
259 if 'init' in self and not 'init' in exclude:
260 text = self['init']
261 ff.write('<%(tag)s>\n%(text)s\n</%(tag)s>\n' % \
262 {'tag':'init', 'text':text.strip()})
263 if close_tag:
264 ff.write('</LesHouchesEvents>\n')
265 return ff
266
267
268
269
270
271 - def add(self, path, tag=None):
272 """Add the content of the file to the banner"""
273
274 if not tag:
275 card_name = os.path.basename(path)
276 if 'param_card' in card_name:
277 tag = 'slha'
278 elif 'run_card' in card_name:
279 tag = 'MGRunCard'
280 elif 'pythia_card' in card_name:
281 tag = 'MGPythiaCard'
282 elif 'pgs_card' in card_name:
283 tag = 'MGPGSCard'
284 elif 'delphes_card' in card_name:
285 tag = 'MGDelphesCard'
286 elif 'delphes_trigger' in card_name:
287 tag = 'MGDelphesTrigger'
288 elif 'proc_card_mg5' in card_name:
289 tag = 'MG5ProcCard'
290 elif 'proc_card' in card_name:
291 tag = 'MGProcCard'
292 elif 'procdef_mg5' in card_name:
293 tag = 'MGProcCard'
294 elif 'shower_card' in card_name:
295 tag = 'MGShowerCard'
296 elif 'madspin_card' in card_name:
297 tag = 'madspin'
298 elif 'FO_analyse_card' in card_name:
299 tag = 'foanalyse'
300 else:
301 raise Exception, 'Impossible to know the type of the card'
302
303 self.add_text(tag.lower(), open(path).read())
304
305 - def add_text(self, tag, text):
306 """Add the content of the file to the banner"""
307
308 if tag == 'param_card':
309 tag = 'slha'
310 elif tag == 'run_card':
311 tag = 'mgruncard'
312 elif tag == 'proc_card':
313 tag = 'mg5proccard'
314 elif tag == 'shower_card':
315 tag = 'mgshowercard'
316 elif tag == 'FO_analyse_card':
317 tag = 'foanalyse'
318
319 self[tag.lower()] = text
320
321
375
376
378 """return a specific """
379
380 if tag == 'param_card':
381 tag = 'slha'
382 attr_tag = 'param_card'
383 elif tag == 'run_card':
384 tag = 'mgruncard'
385 attr_tag = 'run_card'
386 elif tag == 'proc_card':
387 tag = 'mg5proccard'
388 attr_tag = 'proc_card'
389 elif tag == 'model':
390 tag = 'mg5proccard'
391 attr_tag = 'proc_card'
392 arg = ('model',)
393 elif tag == 'generate':
394 tag = 'mg5proccard'
395 attr_tag = 'proc_card'
396 arg = ('generate',)
397 elif tag == 'shower_card':
398 tag = 'mgshowercard'
399 attr_tag = 'shower_card'
400 assert tag in ['slha', 'mgruncard', 'mg5proccard', 'shower_card'], 'not recognized'
401
402 if not hasattr(self, attr_tag):
403 self.charge_card(attr_tag)
404
405 card = getattr(self, attr_tag)
406 if len(arg) == 1:
407 if tag == 'mg5proccard':
408 try:
409 return card.info[arg[0]]
410 except KeyError, error:
411 if 'default' in opt:
412 return opt['default']
413 else:
414 raise
415 try:
416 return card[arg[0]]
417 except KeyError:
418 if 'default' in opt:
419 return opt['default']
420 else:
421 raise
422 elif len(arg) == 2 and tag == 'slha':
423 try:
424 return card[arg[0]].get(arg[1:])
425 except KeyError:
426 if 'default' in opt:
427 return opt['default']
428 else:
429 raise
430 elif len(arg) == 0:
431 return card
432 else:
433 raise Exception, "Unknow command"
434
435
436 get = get_detail
437
438 - def set(self, card, *args):
439 """modify one of the cards"""
440
441 if tag == 'param_card':
442 tag = 'slha'
443 attr_tag = 'param_card'
444 elif tag == 'run_card':
445 tag = 'mgruncard'
446 attr_tag = 'run_card'
447 elif tag == 'proc_card':
448 tag = 'mg5proccard'
449 attr_tag = 'proc_card'
450 elif tag == 'model':
451 tag = 'mg5proccard'
452 attr_tag = 'proc_card'
453 arg = ('model',)
454 elif tag == 'generate':
455 tag = 'mg5proccard'
456 attr_tag = 'proc_card'
457 arg = ('generate',)
458 elif tag == 'shower_card':
459 tag = 'mgshowercard'
460 attr_tag = 'shower_card'
461 assert tag in ['slha', 'mgruncard', 'mg5proccard', 'shower_card'], 'not recognized'
462
463 if not hasattr(self, attr_tag):
464 self.charge_card(attr_tag)
465
466 card = getattr(self, attr_tag)
467 if len(args) ==2:
468 if tag == 'mg5proccard':
469 card.info[args[0]] = args[-1]
470 else:
471 card[args[0]] = args[1]
472 else:
473 card[args[:-1]] = args[-1]
474
475
476 @misc.multiple_try()
478 """Add the banner to a file and change the associate seed in the banner"""
479
480 if seed is not None:
481 self.set("run_card", "iseed", seed)
482
483 ff = self.write("%s.tmp" % path, close_tag=False,
484 exclude=['MGGenerationInfo', '/header', 'init'])
485 ff.write("## END BANNER##\n")
486 if self.lhe_version >= 3:
487
488 [ff.write(line) if not line.startswith("<generator name='MadGraph5_aMC@NLO'")
489 else ff.write("<generator name='MadGraph5_aMC@NLO' version='%s'>" % self['mgversion'][:-1])
490 for line in open(path)]
491 else:
492 [ff.write(line) for line in open(path)]
493 ff.write("</LesHouchesEvents>\n")
494 ff.close()
495 files.mv("%s.tmp" % path, path)
496
497
498
499 -def split_banner(banner_path, me_dir, proc_card=True):
504
506 """as input we receive a gen_crossxhtml.AllResults object.
507 This define the current banner and load it
508 """
509
510 if not run:
511 try:
512 tag = results_object.current['tag']
513 except Exception:
514 return Banner()
515 if not tag:
516 try:
517 tag = results_object[run].tags[-1]
518 except Exception,error:
519 return Banner()
520 path = results_object.path
521 banner_path = pjoin(path,'Events',run,'%s_%s_banner.txt' % (run, tag))
522
523 if not os.path.exists(banner_path):
524
525 return Banner()
526 banner = Banner(banner_path)
527
528
529
530 if level == 'pythia':
531 if 'mgpythiacard' in banner:
532 del banner['mgpythiacard']
533 if level in ['pythia','pgs','delphes']:
534 for tag in ['mgpgscard', 'mgdelphescard', 'mgdelphestrigger']:
535 if tag in banner:
536 del banner[tag]
537 return banner
538
543
545 """A class object for the run_card"""
546
547
548 hidden_param = ['lhaid', 'gridrun', 'fixed_couplings']
549 true = ['true', 'True','.true.','T', True, 1,'TRUE']
550
552 """ """
553
554 if isinstance(run_card, str):
555 run_card = file(run_card,'r')
556 else:
557 pass
558
559 for line in run_card:
560 line = line.split('#')[0]
561 line = line.split('!')[0]
562 line = line.split('=')
563 if len(line) != 2:
564 continue
565 self[line[1].strip()] = line[0].replace('\'','').strip()
566
568 """return self[name] if exist otherwise default. log control if we
569 put a warning or not if we use the default value"""
570
571 try:
572 return self[name]
573 except KeyError:
574 if log_level:
575 logger.log(log_level, 'run_card missed argument %s. Takes default: %s'
576 % (name, default))
577 self[name] = default
578 return default
579
580 @staticmethod
607
608
609
610 - def write(self, output_file, template=None):
611 """Write the run_card in output_file according to template
612 (a path to a valid run_card)"""
613
614 if not template:
615 template = output_file
616
617 text = ""
618 for line in file(template,'r'):
619 nline = line.split('#')[0]
620 nline = nline.split('!')[0]
621 comment = line[len(nline):]
622 nline = nline.split('=')
623 if len(nline) != 2:
624 text += line
625 elif nline[1].strip() in self:
626 text += ' %s\t= %s %s' % (self[nline[1].strip()],nline[1], comment)
627 else:
628 logger.info('Adding missing parameter %s to current run_card (with default value)' % nline[1].strip())
629 text += line
630
631 for param in self.hidden_param:
632 if param in self:
633 text += ' %s\t= %s \n' % (self[param],param)
634
635 fsock = open(output_file,'w')
636 fsock.write(text)
637 fsock.close()
638
639
641 """writing the run_card.inc file"""
642
643 self.fsock = file_writers.FortranWriter(output_path)
644
645
646
647
648 self.add_line('ptgmin', 'float', 0.0)
649 self.add_line('R0gamma', 'float', 0.4)
650 self.add_line('xn', 'float', 1.0)
651 self.add_line('epsgamma', 'float', 1.0)
652 self.add_line('isoEM', 'bool', True)
653
654 if 'ptgmin' in self and float(self['ptgmin'])>0:
655 if float(self['pta']) > 0:
656 logger.warning('pta cut discarded since photon isolation is used')
657 self['pta'] = '0'
658 if float(self['draj']) > 0:
659 logger.warning('draj cut discarded since photon isolation is used')
660 self['draj'] = '0'
661
662 self.add_line('maxjetflavor', 'int', 4)
663 if int(self['maxjetflavor']) > 6:
664 raise InvalidRunCard, 'maxjetflavor should be lower than 5! (6 is partly supported)'
665 self.add_line('auto_ptj_mjj', 'bool', True)
666 self.add_line('cut_decays', 'bool', True)
667
668 self.add_line('ptj', 'float', 20)
669 self.add_line('ptb', 'float', 20)
670 self.add_line('pta', 'float', 20)
671 self.add_line('ptl', 'float', 20)
672 self.add_line('misset', 'float', 0)
673 self.add_line('ptonium', 'float', 0.0)
674
675 self.add_line('ptjmax', 'float', -1)
676 self.add_line('ptbmax', 'float', -1)
677 self.add_line('ptamax', 'float', -1)
678 self.add_line('ptlmax', 'float', -1)
679 self.add_line('missetmax', 'float', -1)
680
681 self.add_line('etaj', 'float', 4.0)
682 self.add_line('etab', 'float', 4.0)
683 self.add_line('etaa', 'float', 4.0)
684 self.add_line('etal', 'float', 4.0)
685
686 self.add_line('etajmin', 'float', 0.0)
687 self.add_line('etabmin', 'float', 0.0)
688 self.add_line('etaamin', 'float', 0.0)
689 self.add_line('etalmin', 'float', 0.0)
690 self.add_line('etaonium', 'float', 100.0)
691
692 self.add_line('ej', 'float', 0.0)
693 self.add_line('eb', 'float', 0.0)
694 self.add_line('ea', 'float', 0.0)
695 self.add_line('el', 'float', 0.0)
696
697 self.add_line('ejmax', 'float', -1)
698 self.add_line('ebmax', 'float', -1)
699 self.add_line('eamax', 'float', -1)
700 self.add_line('elmax', 'float', -1)
701
702 self.add_line('drjj', 'float', 0.4)
703 self.add_line('drbb', 'float', 0.4)
704 self.add_line('drll', 'float', 0.4)
705 self.add_line('draa', 'float', 0.4)
706 self.add_line('drbj', 'float', 0.4)
707 self.add_line('draj', 'float', 0.4)
708 self.add_line('drjl', 'float', 0.4)
709 self.add_line('drab', 'float', 0.4)
710 self.add_line('drbl', 'float', 0.4)
711 self.add_line('dral', 'float', 0.4)
712
713 self.add_line('drjjmax', 'float', -1)
714 self.add_line('drbbmax', 'float', -1)
715 self.add_line('drllmax', 'float', -1)
716 self.add_line('draamax', 'float', -1)
717 self.add_line('drbjmax', 'float', -1)
718 self.add_line('drajmax', 'float', -1)
719 self.add_line('drjlmax', 'float', -1)
720 self.add_line('drabmax', 'float', -1)
721 self.add_line('drblmax', 'float', -1)
722 self.add_line('dralmax', 'float', -1)
723
724 self.add_line('mmjj', 'float', 0.0)
725 self.add_line('mmbb', 'float', 0.0)
726 self.add_line('mmaa', 'float', 0.0)
727 self.add_line('mmll', 'float', 0.0)
728
729 self.add_line('mmjjmax', 'float', -1)
730 self.add_line('mmbbmax', 'float', -1)
731 self.add_line('mmaamax', 'float', -1)
732 self.add_line('mmllmax', 'float', -1)
733
734 self.add_line("mmnl", 'float', 0.0)
735 self.add_line("mmnlmax", 'float', -1)
736
737 self.add_line("xptj", 'float', 0.0)
738 self.add_line("xptb", 'float', 0.0)
739 self.add_line("xpta", 'float', 0.0)
740 self.add_line("xptl", 'float', 0.0)
741 self.add_line("xmtcentral", 'float', 0.0, fortran_name='xmtc', log=10)
742
743 self.add_line("xetamin", 'float', 0.0)
744 self.add_line("deltaeta", 'float', 0.0)
745
746 self.add_line("xqcut", 'float', 0.0)
747 self.add_line("d", 'float', 1.0, log=10)
748
749 self.add_line("ptheavy", 'float', 0.0)
750
751 self.add_line("ptllmin", "float", 0.0)
752 self.add_line("ptllmax", "float", -1)
753
754 self.add_line("ptj1min", "float", 0.0)
755 self.add_line("ptj1max", "float", -1)
756 self.add_line("ptj2min", "float", 0.0)
757 self.add_line("ptj2max", "float", -1)
758 self.add_line("ptj3min", "float", 0.0)
759 self.add_line("ptj3max", "float", -1)
760 self.add_line("ptj4min", "float", 0.0)
761 self.add_line("ptj4max", "float", -1)
762 self.add_line("cutuse", "float", 0.0)
763
764 self.add_line("ptl1min", "float", 0.0)
765 self.add_line("ptl1max", "float", -1)
766 self.add_line("ptl2min", "float", 0.0)
767 self.add_line("ptl2max", "float", -1)
768 self.add_line("ptl3min", "float", 0.0)
769 self.add_line("ptl3max", "float", -1)
770 self.add_line("ptl4min", "float", 0.0)
771 self.add_line("ptl4max", "float", -1)
772
773 self.add_line("ht2min", 'float', 0.0)
774 self.add_line("ht3min", 'float', 0.0)
775 self.add_line("ht4min", 'float', 0.0)
776 self.add_line("ht2max", 'float', -1)
777 self.add_line("ht3max", 'float', -1)
778 self.add_line("ht4max", 'float', -1)
779 self.add_line("htjmin", 'float', 0.0)
780 self.add_line("htjmax", 'float', -1)
781 self.add_line("ihtmin", 'float', 0.0)
782 self.add_line("ihtmax", 'float', -1)
783
784 self.add_line('ktdurham', 'float', -1, fortran_name='kt_durham')
785 self.add_line('dparameter', 'float', 0.4, fortran_name='d_parameter')
786
787
788
789
790
791
792 self.add_line("lhe_version", "float", 2.0)
793
794 self.add_line("gridpack","bool", False)
795 self.add_line("gridrun",'bool', False, log=10)
796 if str(self['gridrun']) in ['1','T','.true','True'] and \
797 str(self['gridpack']) in ['1','T','.true','True']:
798 self.add_line('gseed', 'int', 0, fortran_name='iseed')
799 else:
800 self.add_line('iseed', 'int', 0, fortran_name='iseed')
801
802 self.add_line('nevents', 'int', 10000)
803
804
805
806 self.add_line('fixed_ren_scale', 'bool', True)
807 self.add_line('fixed_fac_scale', 'bool', True)
808 self.add_line('scale', 'float', 'float', 91.188)
809 self.add_line('dsqrt_q2fact1','float', 91.188, fortran_name='sf1')
810 self.add_line('dsqrt_q2fact2', 'float', 91.188, fortran_name='sf2')
811
812 self.add_line('use_syst', 'bool', False)
813
814 if self['use_syst'] in self.true:
815 value = self.format('float',self.get_default('scalefact', 1.0, 30))
816 if value != self.format('float', 1.0):
817 logger.warning('Since use_syst=T, We change the value of \'scalefact\' to 1')
818 self['scalefact'] = 1.0
819 self.add_line('scalefact', 'float', 1.0)
820
821 self.add_line('fixed_couplings', 'bool', True, log=10)
822 self.add_line('ickkw', 'int', 0)
823 self.add_line('chcluster', 'bool', False)
824 self.add_line('ktscheme', 'int', 1)
825 self.add_line('asrwgtflavor', 'int', 5)
826
827
828 if int(self['ickkw'])>0:
829
830 if self['use_syst'] in self.true:
831 value = self.format('float',self.get_default('alpsfact', 1.0, 30))
832 if value != self.format('float', 1.0):
833 logger.warning('Since use_syst=T, We change the value of \'alpsfact\' to 1')
834 self['alpsfact'] = 1.0
835 if int(self['maxjetflavor']) == 6:
836 raise InvalidRUnCard, 'maxjetflavor at 6 is NOT supported for matching!'
837 self.add_line('alpsfact', 'float', 1.0)
838 self.add_line('pdfwgt', 'bool', True)
839 self.add_line('clusinfo', 'bool', False)
840
841 if self.format('float', self['drjj']) != self.format('float', 0.):
842 logger.warning('Since icckw>0, We change the value of \'drjj\' to 0')
843 if self.format('float', self['drjl']) != self.format('float', 0.):
844 logger.warning('Since icckw>0, We change the value of \'drjl\' to 0')
845 if self.format('bool', self['auto_ptj_mjj']) == '.false.':
846
847 mmjj = self['mmjj']
848 if isinstance(mmjj,str):
849 mmjj = float(mmjj.replace('d','e'))
850 xqcut = self['xqcut']
851 if isinstance(xqcut,str):
852 xqcut = float(xqcut.replace('d','e'))
853
854 if mmjj > xqcut:
855 logger.warning('mmjj > xqcut (and auto_ptj_mjj = F). MMJJ set to 0')
856 self.add_line('mmjj','float',0)
857
858 if int(self['ickkw'])==2:
859 self.add_line('highestmult','int', 0, fortran_name='nhmult')
860 self.add_line('issgridfile','str','issudgrid.dat')
861
862
863 self.add_line('lpp1', 'int', 1, fortran_name='lpp(1)')
864 self.add_line('lpp2', 'int', 1, fortran_name='lpp(2)')
865 self.add_line('ebeam1', 'float', 7000, fortran_name='ebeam(1)')
866 self.add_line('ebeam2', 'float', 7000, fortran_name='ebeam(2)')
867
868 self.add_line('polbeam1', 'float', 0.0, fortran_name='pb1')
869 self.add_line('polbeam2', 'float', 0.0, fortran_name='pb2')
870
871 self.add_line('bwcutoff', 'float', 15.0)
872
873 self.add_line('pdlabel','str','cteq6l1')
874
875
876 possible_set = ['lhapdf','mrs02nl','mrs02nn', 'mrs0119','mrs0117','mrs0121','mrs01_j', 'mrs99_1','mrs99_2','mrs99_3','mrs99_4','mrs99_5','mrs99_6', 'mrs99_7','mrs99_8','mrs99_9','mrs9910','mrs9911','mrs9912', 'mrs98z1','mrs98z2','mrs98z3','mrs98z4','mrs98z5','mrs98ht', 'mrs98l1','mrs98l2','mrs98l3','mrs98l4','mrs98l5', 'cteq3_m','cteq3_l','cteq3_d', 'cteq4_m','cteq4_d','cteq4_l','cteq4a1','cteq4a2', 'cteq4a3','cteq4a4','cteq4a5','cteq4hj','cteq4lq', 'cteq5_m','cteq5_d','cteq5_l','cteq5hj','cteq5hq', 'cteq5f3','cteq5f4','cteq5m1','ctq5hq1','cteq5l1', 'cteq6_m','cteq6_d','cteq6_l','cteq6l1', 'nn23lo','nn23lo1','nn23nlo']
877 if self['pdlabel'] not in possible_set:
878 raise InvalidRunCard, 'Invalid PDF set (argument of pdlabel) possible choice are:\n %s' % ','.join(possible_set)
879
880 if self['pdlabel'] == 'lhapdf':
881 self.add_line('lhaid', 'int', 10042)
882 else:
883 self.add_line('lhaid', 'int', 10042, log=10)
884
885 self.fsock.close()
886
887
888
889
890 - def add_line(self, card_name, type, default, log=30, fortran_name=None):
891 """get the line for the .inc file"""
892
893 value = self.get_default(card_name, default, log)
894 if not fortran_name:
895 fortran_name = card_name
896 self.fsock.writelines(' %s = %s \n' % (fortran_name, self.format(type, value)))
897
900 """A class object for the run_card for a (aMC@)NLO pocess"""
901
902
904 """writing the run_card.inc file"""
905
906
907 true = ['true', 'True','.true.','T', True, 1,'TRUE']
908 if int(self['ickkw']) == 3:
909
910 scales=['fixed_ren_scale','fixed_fac_scale','fixed_QES_scale']
911 for scale in scales:
912 if self[scale] in true :
913 logger.info('''For consistency in the FxFx merging, \'%s\' has been set to false'''
914 % scale,'$MG:color:BLACK')
915 self[scale]='F'
916
917 jetparams=['jetradius','jetalgo']
918 for jetparam in jetparams:
919 if float(self[jetparam]) != 1.0:
920 logger.info('''For consistency in the FxFx merging, \'%s\' has been set to 1.0'''
921 % jetparam ,'$MG:color:BLACK')
922 self[jetparam]='1.0'
923
924
925 self.get_default('iappl', '0', log_level=10)
926
927 if self['iappl'] != '0' and self['pdlabel'].lower() != 'lhapdf':
928 raise self.InvalidCmd('APPLgrid generation only possible with the use of LHAPDF')
929 if self['iappl'] != '0' and self['reweight_scale'] not in true:
930 raise self.InvalidCmd('APPLgrid generation only possible with including' +\
931 ' the reweighting to get scale dependence')
932
933 self.fsock = file_writers.FortranWriter(output_path)
934
935
936
937
938 self.add_line('maxjetflavor', 'int', 4)
939
940 self.add_line('ptj', 'float', 20)
941 self.add_line('etaj', 'float', -1.0)
942 self.add_line('ptl', 'float', 20)
943 self.add_line('etal', 'float', -1.0)
944
945 self.add_line('drll', 'float', 0.4)
946 self.add_line('drll_sf', 'float', 0.4)
947
948 self.add_line('mll', 'float', 0.0)
949 self.add_line('mll_sf', 'float', 0.0)
950
951
952 self.add_line("jetradius", 'float', 0.7, log=10)
953
954
955
956
957
958 self.add_line('iseed', 'int', 0)
959 self.add_line('parton_shower', 'str', 'HERWIG6', fortran_name='shower_mc')
960 self.add_line('nevents', 'int', 10000)
961 self.add_line('event_norm', 'str', 'average', fortran_name='event_norm')
962
963 self.add_line('fixed_ren_scale', 'bool', True)
964 self.add_line('fixed_fac_scale', 'bool', True)
965 self.add_line('fixed_QES_scale', 'bool', True)
966 self.add_line('muR_ref_fixed', 'float', 91.188)
967 self.add_line('muF1_ref_fixed','float', 91.188)
968 self.add_line('muF2_ref_fixed', 'float', 91.188)
969 self.add_line('QES_ref_fixed', 'float', 91.188)
970 self.add_line('muR_over_ref', 'float', 1.0)
971 self.add_line('muF1_over_ref', 'float', 1.0)
972 self.add_line('muF2_over_ref', 'float', 1.0)
973 self.add_line('QES_over_ref', 'float', 1.0)
974
975 self.add_line('reweight_scale', 'bool', True, fortran_name='do_rwgt_scale')
976 self.add_line('rw_Rscale_up', 'float', 2.0)
977 self.add_line('rw_Rscale_down', 'float', 0.5)
978 self.add_line('rw_Fscale_up', 'float', 2.0)
979 self.add_line('rw_Fscale_down', 'float', 0.5)
980 self.add_line('reweight_PDF', 'bool', True, fortran_name='do_rwgt_pdf')
981 self.add_line('PDF_set_min', 'int', 21101)
982 self.add_line('PDF_set_max', 'int', 21140)
983 self.add_line('iappl', 'int', 0)
984
985 self.add_line('ickkw', 'int', 0)
986 self.add_line('jetalgo', 'float', 1.0)
987
988 self.add_line('lpp1', 'int', 1, fortran_name='lpp(1)')
989 self.add_line('lpp2', 'int', 1, fortran_name='lpp(2)')
990 self.add_line('ebeam1', 'float', 4000, fortran_name='ebeam(1)')
991 self.add_line('ebeam2', 'float', 4000, fortran_name='ebeam(2)')
992
993 self.add_line('bwcutoff', 'float', 15.0)
994
995 self.add_line('ptgmin', 'float', 10.0)
996 self.add_line('etagamma', 'float', -1.0)
997 self.add_line('R0gamma', 'float', 0.4)
998 self.add_line('xn', 'float', 1.0)
999 self.add_line('epsgamma', 'float', 1.0)
1000 self.add_line('isoEM', 'bool', True)
1001
1002 self.add_line('pdlabel','str','cteq6_m')
1003
1004 possible_set = ['lhapdf','mrs02nl','mrs02nn', 'mrs0119','mrs0117','mrs0121','mrs01_j', 'mrs99_1','mrs99_2','mrs99_3','mrs99_4','mrs99_5','mrs99_6', 'mrs99_7','mrs99_8','mrs99_9','mrs9910','mrs9911','mrs9912', 'mrs98z1','mrs98z2','mrs98z3','mrs98z4','mrs98z5','mrs98ht', 'mrs98l1','mrs98l2','mrs98l3','mrs98l4','mrs98l5', 'cteq3_m','cteq3_l','cteq3_d', 'cteq4_m','cteq4_d','cteq4_l','cteq4a1','cteq4a2', 'cteq4a3','cteq4a4','cteq4a5','cteq4hj','cteq4lq', 'cteq5_m','cteq5_d','cteq5_l','cteq5hj','cteq5hq', 'cteq5f3','cteq5f4','cteq5m1','ctq5hq1','cteq5l1', 'cteq6_m','cteq6_d','cteq6_l','cteq6l1', 'nn23lo','nn23lo1','nn23nlo']
1005 if self['pdlabel'] not in possible_set:
1006 raise InvalidRunCard, 'Invalid PDF set (argument of pdlabel) possible choice are:\n %s' % ','.join(possible_set)
1007
1008
1009
1010 if self['pdlabel'] == 'lhapdf':
1011 self.add_line('lhaid', 'int', 21100)
1012 else:
1013 self.add_line('lhaid', 'int', 21100, log=10)
1014
1015 self.fsock.close()
1016
1018 """Basic Proccard object"""
1019
1020 history_header = \
1021 '#************************************************************\n' + \
1022 '#* MadGraph5_aMC@NLO *\n' + \
1023 '#* *\n' + \
1024 "#* * * *\n" + \
1025 "#* * * * * *\n" + \
1026 "#* * * * * 5 * * * * *\n" + \
1027 "#* * * * * *\n" + \
1028 "#* * * *\n" + \
1029 "#* *\n" + \
1030 "#* *\n" + \
1031 "%(info_line)s" +\
1032 "#* *\n" + \
1033 "#* The MadGraph5_aMC@NLO Development Team - Find us at *\n" + \
1034 "#* https://server06.fynu.ucl.ac.be/projects/madgraph *\n" + \
1035 '#* *\n' + \
1036 '#************************************************************\n' + \
1037 '#* *\n' + \
1038 '#* Command File for MadGraph5_aMC@NLO *\n' + \
1039 '#* *\n' + \
1040 '#* run as ./bin/mg5_aMC filename *\n' + \
1041 '#* *\n' + \
1042 '#************************************************************\n'
1043
1044
1045
1046
1048 """ initialize a basic proc_card"""
1049 self.info = {'model': 'sm', 'generate':None,
1050 'full_model_line':'import model sm'}
1051 list.__init__(self)
1052 if init:
1053 self.read(init)
1054
1055
1056 - def read(self, init):
1057 """read the proc_card and save the information"""
1058
1059 if isinstance(init, str):
1060 init = file(init, 'r')
1061
1062 store_line = ''
1063 for line in init:
1064 line = line.strip()
1065 if line.endswith('\\'):
1066 store_line += line[:-1]
1067 else:
1068 self.append(store_line + line)
1069 store_line = ""
1070 if store_line:
1071 raise Exception, "WRONG CARD FORMAT"
1073 """move an element to the last history."""
1074 for line in self[:]:
1075 if line.startswith(cmd):
1076 self.remove(line)
1077 list.append(self, line)
1078
1080 """"add a line in the proc_card perform automatically cleaning"""
1081
1082 line = line.strip()
1083 cmds = line.split()
1084 if len(cmds) == 0:
1085 return
1086
1087 list.append(self, line)
1088
1089
1090 cmd = cmds[0]
1091
1092 if cmd == 'output':
1093
1094 self.clean(allow_for_removal = ['output'], keep_switch=True,
1095 remove_bef_last='output')
1096 elif cmd == 'generate':
1097
1098 self.clean(remove_bef_last='generate', keep_switch=True,
1099 allow_for_removal= ['generate', 'add process', 'output'])
1100 self.info['generate'] = ' '.join(cmds[1:])
1101 elif cmd == 'add' and cmds[1] == 'process' and not self.info['generate']:
1102 self.info['generate'] = ' '.join(cmds[2:])
1103 elif cmd == 'import':
1104 if len(cmds) < 2:
1105 return
1106 if cmds[1].startswith('model'):
1107 self.info['full_model_line'] = line
1108 self.clean(remove_bef_last='import', keep_switch=True,
1109 allow_for_removal=['generate', 'add process', 'add model', 'output'])
1110 if cmds[1] == 'model':
1111 self.info['model'] = cmds[2]
1112 else:
1113 self.info['model'] = None
1114 elif cmds[1] == 'proc_v4':
1115
1116 self[:] = []
1117
1118
1119 - def clean(self, to_keep=['set','add','load'],
1120 remove_bef_last=None,
1121 to_remove=['open','display','launch', 'check','history'],
1122 allow_for_removal=None,
1123 keep_switch=False):
1124 """Remove command in arguments from history.
1125 All command before the last occurrence of 'remove_bef_last'
1126 (including it) will be removed (but if another options tells the opposite).
1127 'to_keep' is a set of line to always keep.
1128 'to_remove' is a set of line to always remove (don't care about remove_bef_
1129 status but keep_switch acts.).
1130 if 'allow_for_removal' is define only the command in that list can be
1131 remove of the history for older command that remove_bef_lb1. all parameter
1132 present in to_remove are always remove even if they are not part of this
1133 list.
1134 keep_switch force to keep the statement remove_bef_??? which changes starts
1135 the removal mode.
1136 """
1137
1138
1139 if __debug__ and allow_for_removal:
1140 for arg in to_keep:
1141 assert arg not in allow_for_removal
1142
1143
1144 nline = -1
1145 removal = False
1146
1147 while nline > -len(self):
1148 switch = False
1149
1150
1151 if not removal and remove_bef_last:
1152 if self[nline].startswith(remove_bef_last):
1153 removal = True
1154 switch = True
1155
1156
1157 if switch and keep_switch:
1158 nline -= 1
1159 continue
1160
1161
1162 if any([self[nline].startswith(arg) for arg in to_remove]):
1163 self.pop(nline)
1164 continue
1165
1166
1167 if removal:
1168 if allow_for_removal:
1169
1170 if any([self[nline].startswith(arg)
1171 for arg in allow_for_removal]):
1172 self.pop(nline)
1173 continue
1174 elif not any([self[nline].startswith(arg) for arg in to_keep]):
1175
1176 self.pop(nline)
1177 continue
1178
1179
1180 nline -= 1
1181
1189
1191 """write the proc_card to a given path"""
1192
1193 fsock = open(path, 'w')
1194 fsock.write(self.history_header)
1195 for line in self:
1196 while len(line) > 70:
1197 sub, line = line[:70]+"\\" , line[70:]
1198 fsock.write(sub+"\n")
1199 else:
1200 fsock.write(line+"\n")
1201