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
600
601
602
603 - def write(self, output_file, template=None):
604 """Write the run_card in output_file according to template
605 (a path to a valid run_card)"""
606
607 if not template:
608 template = output_file
609
610 text = ""
611 for line in file(template,'r'):
612 nline = line.split('#')[0]
613 nline = nline.split('!')[0]
614 comment = line[len(nline):]
615 nline = nline.split('=')
616 if len(nline) != 2:
617 text += line
618 elif nline[1].strip() in self:
619 text += ' %s\t= %s %s' % (self[nline[1].strip()],nline[1], comment)
620 else:
621 logger.info('Adding missing parameter %s to current run_card (with default value)' % nline[1].strip())
622 text += line
623
624 for param in self.hidden_param:
625 if param in self:
626 text += ' %s\t= %s \n' % (self[param],param)
627
628 fsock = open(output_file,'w')
629 fsock.write(text)
630 fsock.close()
631
632
634 """writing the run_card.inc file"""
635
636 self.fsock = file_writers.FortranWriter(output_path)
637
638
639
640
641 self.add_line('ptgmin', 'float', 0.0)
642 self.add_line('R0gamma', 'float', 0.4)
643 self.add_line('xn', 'float', 1.0)
644 self.add_line('epsgamma', 'float', 1.0)
645 self.add_line('isoEM', 'bool', True)
646
647 if 'ptgmin' in self and float(self['ptgmin'])>0:
648 if float(self['pta']) > 0:
649 logger.warning('pta cut discarded since photon isolation is used')
650 self['pta'] = '0'
651 if float(self['draj']) > 0:
652 logger.warning('draj cut discarded since photon isolation is used')
653 self['draj'] = '0'
654
655 self.add_line('maxjetflavor', 'int', 4)
656 if int(self['maxjetflavor']) > 6:
657 raise InvalidRunCard, 'maxjetflavor should be lower than 5! (6 is partly supported)'
658 self.add_line('auto_ptj_mjj', 'bool', True)
659 self.add_line('cut_decays', 'bool', True)
660
661 self.add_line('ptj', 'float', 20)
662 self.add_line('ptb', 'float', 20)
663 self.add_line('pta', 'float', 20)
664 self.add_line('ptl', 'float', 20)
665 self.add_line('misset', 'float', 0)
666 self.add_line('ptonium', 'float', 0.0)
667
668 self.add_line('ptjmax', 'float', -1)
669 self.add_line('ptbmax', 'float', -1)
670 self.add_line('ptamax', 'float', -1)
671 self.add_line('ptlmax', 'float', -1)
672 self.add_line('missetmax', 'float', -1)
673
674 self.add_line('etaj', 'float', 4.0)
675 self.add_line('etab', 'float', 4.0)
676 self.add_line('etaa', 'float', 4.0)
677 self.add_line('etal', 'float', 4.0)
678
679 self.add_line('etajmin', 'float', 0.0)
680 self.add_line('etabmin', 'float', 0.0)
681 self.add_line('etaamin', 'float', 0.0)
682 self.add_line('etalmin', 'float', 0.0)
683 self.add_line('etaonium', 'float', 100.0)
684
685 self.add_line('ej', 'float', 0.0)
686 self.add_line('eb', 'float', 0.0)
687 self.add_line('ea', 'float', 0.0)
688 self.add_line('el', 'float', 0.0)
689
690 self.add_line('ejmax', 'float', -1)
691 self.add_line('ebmax', 'float', -1)
692 self.add_line('eamax', 'float', -1)
693 self.add_line('elmax', 'float', -1)
694
695 self.add_line('drjj', 'float', 0.4)
696 self.add_line('drbb', 'float', 0.4)
697 self.add_line('drll', 'float', 0.4)
698 self.add_line('draa', 'float', 0.4)
699 self.add_line('drbj', 'float', 0.4)
700 self.add_line('draj', 'float', 0.4)
701 self.add_line('drjl', 'float', 0.4)
702 self.add_line('drab', 'float', 0.4)
703 self.add_line('drbl', 'float', 0.4)
704 self.add_line('dral', 'float', 0.4)
705
706 self.add_line('drjjmax', 'float', -1)
707 self.add_line('drbbmax', 'float', -1)
708 self.add_line('drllmax', 'float', -1)
709 self.add_line('draamax', 'float', -1)
710 self.add_line('drbjmax', 'float', -1)
711 self.add_line('drajmax', 'float', -1)
712 self.add_line('drjlmax', 'float', -1)
713 self.add_line('drabmax', 'float', -1)
714 self.add_line('drblmax', 'float', -1)
715 self.add_line('dralmax', 'float', -1)
716
717 self.add_line('mmjj', 'float', 0.0)
718 self.add_line('mmbb', 'float', 0.0)
719 self.add_line('mmaa', 'float', 0.0)
720 self.add_line('mmll', 'float', 0.0)
721
722 self.add_line('mmjjmax', 'float', -1)
723 self.add_line('mmbbmax', 'float', -1)
724 self.add_line('mmaamax', 'float', -1)
725 self.add_line('mmllmax', 'float', -1)
726
727 self.add_line("mmnl", 'float', 0.0)
728 self.add_line("mmnlmax", 'float', -1)
729
730 self.add_line("xptj", 'float', 0.0)
731 self.add_line("xptb", 'float', 0.0)
732 self.add_line("xpta", 'float', 0.0)
733 self.add_line("xptl", 'float', 0.0)
734 self.add_line("xmtcentral", 'float', 0.0, fortran_name='xmtc', log=10)
735
736 self.add_line("xetamin", 'float', 0.0)
737 self.add_line("deltaeta", 'float', 0.0)
738
739 self.add_line("xqcut", 'float', 0.0)
740 self.add_line("d", 'float', 1.0, log=10)
741
742 self.add_line("ptheavy", 'float', 0.0)
743
744 self.add_line("ptllmin", "float", 0.0)
745 self.add_line("ptllmax", "float", -1)
746
747 self.add_line("ptj1min", "float", 0.0)
748 self.add_line("ptj1max", "float", -1)
749 self.add_line("ptj2min", "float", 0.0)
750 self.add_line("ptj2max", "float", -1)
751 self.add_line("ptj3min", "float", 0.0)
752 self.add_line("ptj3max", "float", -1)
753 self.add_line("ptj4min", "float", 0.0)
754 self.add_line("ptj4max", "float", -1)
755 self.add_line("cutuse", "float", 0.0)
756
757 self.add_line("ptl1min", "float", 0.0)
758 self.add_line("ptl1max", "float", -1)
759 self.add_line("ptl2min", "float", 0.0)
760 self.add_line("ptl2max", "float", -1)
761 self.add_line("ptl3min", "float", 0.0)
762 self.add_line("ptl3max", "float", -1)
763 self.add_line("ptl4min", "float", 0.0)
764 self.add_line("ptl4max", "float", -1)
765
766 self.add_line("ht2min", 'float', 0.0)
767 self.add_line("ht3min", 'float', 0.0)
768 self.add_line("ht4min", 'float', 0.0)
769 self.add_line("ht2max", 'float', -1)
770 self.add_line("ht3max", 'float', -1)
771 self.add_line("ht4max", 'float', -1)
772 self.add_line("htjmin", 'float', 0.0)
773 self.add_line("htjmax", 'float', -1)
774 self.add_line("ihtmin", 'float', 0.0)
775 self.add_line("ihtmax", 'float', -1)
776
777 self.add_line('ktdurham', 'float', -1, fortran_name='kt_durham')
778 self.add_line('dparameter', 'float', 0.4, fortran_name='d_parameter')
779
780
781
782
783
784
785 self.add_line("lhe_version", "float", 2.0)
786
787 self.add_line("gridpack","bool", False)
788 self.add_line("gridrun",'bool', False, log=10)
789 if str(self['gridrun']) in ['1','T','.true','True'] and \
790 str(self['gridpack']) in ['1','T','.true','True']:
791 self.add_line('gseed', 'int', 0, fortran_name='iseed')
792 else:
793 self.add_line('iseed', 'int', 0, fortran_name='iseed')
794
795 self.add_line('nevents', 'int', 10000)
796
797
798
799 self.add_line('fixed_ren_scale', 'bool', True)
800 self.add_line('fixed_fac_scale', 'bool', True)
801 self.add_line('scale', 'float', 'float', 91.188)
802 self.add_line('dsqrt_q2fact1','float', 91.188, fortran_name='sf1')
803 self.add_line('dsqrt_q2fact2', 'float', 91.188, fortran_name='sf2')
804
805 self.add_line('use_syst', 'bool', False)
806
807 if self['use_syst'] in self.true:
808 value = self.format('float',self.get_default('scalefact', 1.0, 30))
809 if value != self.format('float', 1.0):
810 logger.warning('Since use_syst=T, We change the value of \'scalefact\' to 1')
811 self['scalefact'] = 1.0
812 self.add_line('scalefact', 'float', 1.0)
813
814 self.add_line('fixed_couplings', 'bool', True, log=10)
815 self.add_line('ickkw', 'int', 0)
816 self.add_line('chcluster', 'bool', False)
817 self.add_line('ktscheme', 'int', 1)
818 self.add_line('asrwgtflavor', 'int', 5)
819
820
821 if int(self['ickkw'])>0:
822
823 if self['use_syst'] in self.true:
824 value = self.format('float',self.get_default('alpsfact', 1.0, 30))
825 if value != self.format('float', 1.0):
826 logger.warning('Since use_syst=T, We change the value of \'alpsfact\' to 1')
827 self['alpsfact'] = 1.0
828 if int(self['maxjetflavor']) == 6:
829 raise InvalidRUnCard, 'maxjetflavor at 6 is NOT supported for matching!'
830 self.add_line('alpsfact', 'float', 1.0)
831 self.add_line('pdfwgt', 'bool', True)
832 self.add_line('clusinfo', 'bool', False)
833
834 if self.format('float', self['drjj']) != self.format('float', 0.):
835 logger.warning('Since icckw>0, We change the value of \'drjj\' to 0')
836 if self.format('float', self['drjl']) != self.format('float', 0.):
837 logger.warning('Since icckw>0, We change the value of \'drjl\' to 0')
838 if self.format('bool', self['auto_ptj_mjj']) == '.false.':
839
840 mmjj = self['mmjj']
841 if isinstance(mmjj,str):
842 mmjj = float(mmjj.replace('d','e'))
843 xqcut = self['xqcut']
844 if isinstance(xqcut,str):
845 xqcut = float(xqcut.replace('d','e'))
846
847 if mmjj > xqcut:
848 logger.warning('mmjj > xqcut (and auto_ptj_mjj = F). MMJJ set to 0')
849 self.add_line('mmjj','float',0)
850
851 if int(self['ickkw'])==2:
852 self.add_line('highestmult','int', 0, fortran_name='nhmult')
853 self.add_line('issgridfile','str','issudgrid.dat')
854
855
856 self.add_line('lpp1', 'int', 1, fortran_name='lpp(1)')
857 self.add_line('lpp2', 'int', 1, fortran_name='lpp(2)')
858 self.add_line('ebeam1', 'float', 7000, fortran_name='ebeam(1)')
859 self.add_line('ebeam2', 'float', 7000, fortran_name='ebeam(2)')
860
861 self.add_line('polbeam1', 'float', 0.0, fortran_name='pb1')
862 self.add_line('polbeam2', 'float', 0.0, fortran_name='pb2')
863
864 self.add_line('bwcutoff', 'float', 15.0)
865
866 self.add_line('pdlabel','str','cteq6l1')
867
868
869 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']
870 if self['pdlabel'] not in possible_set:
871 raise InvalidRunCard, 'Invalid PDF set (argument of pdlabel) possible choice are:\n %s' % ','.join(possible_set)
872
873 if self['pdlabel'] == 'lhapdf':
874 self.add_line('lhaid', 'int', 10042)
875 else:
876 self.add_line('lhaid', 'int', 10042, log=10)
877
878 self.fsock.close()
879
880
881
882
883 - def add_line(self, card_name, type, default, log=30, fortran_name=None):
884 """get the line for the .inc file"""
885
886 value = self.get_default(card_name, default, log)
887 if not fortran_name:
888 fortran_name = card_name
889 self.fsock.writelines(' %s = %s \n' % (fortran_name, self.format(type, value)))
890
893 """A class object for the run_card for a (aMC@)NLO pocess"""
894
895
897 """writing the run_card.inc file"""
898
899
900 true = ['true', 'True','.true.','T', True, 1,'TRUE']
901 if int(self['ickkw']) == 3:
902
903 scales=['fixed_ren_scale','fixed_fac_scale','fixed_QES_scale']
904 for scale in scales:
905 if self[scale] in true :
906 logger.info('''For consistency in the FxFx merging, \'%s\' has been set to false'''
907 % scale,'$MG:color:BLACK')
908 self[scale]='F'
909
910 jetparams=['jetradius','jetalgo']
911 for jetparam in jetparams:
912 if float(self[jetparam]) != 1.0:
913 logger.info('''For consistency in the FxFx merging, \'%s\' has been set to 1.0'''
914 % jetparam ,'$MG:color:BLACK')
915 self[jetparam]='1.0'
916
917
918 self.get_default('iappl', '0', log_level=10)
919
920 if self['iappl'] != '0' and self['pdlabel'].lower() != 'lhapdf':
921 raise self.InvalidCmd('APPLgrid generation only possible with the use of LHAPDF')
922 if self['iappl'] != '0' and self['reweight_scale'] not in true:
923 raise self.InvalidCmd('APPLgrid generation only possible with including' +\
924 ' the reweighting to get scale dependence')
925
926 self.fsock = file_writers.FortranWriter(output_path)
927
928
929
930
931 self.add_line('maxjetflavor', 'int', 4)
932
933 self.add_line('ptj', 'float', 20)
934 self.add_line('etaj', 'float', -1.0)
935 self.add_line('ptl', 'float', 20)
936 self.add_line('etal', 'float', -1.0)
937
938 self.add_line('drll', 'float', 0.4)
939 self.add_line('drll_sf', 'float', 0.4)
940
941 self.add_line('mll', 'float', 0.0)
942 self.add_line('mll_sf', 'float', 0.0)
943
944
945 self.add_line("jetradius", 'float', 0.7, log=10)
946
947
948
949
950
951 self.add_line('iseed', 'int', 0)
952 self.add_line('parton_shower', 'str', 'HERWIG6', fortran_name='shower_mc')
953 self.add_line('nevents', 'int', 10000)
954 self.add_line('event_norm', 'str', 'average', fortran_name='event_norm')
955
956 self.add_line('fixed_ren_scale', 'bool', True)
957 self.add_line('fixed_fac_scale', 'bool', True)
958 self.add_line('fixed_QES_scale', 'bool', True)
959 self.add_line('muR_ref_fixed', 'float', 91.188)
960 self.add_line('muF1_ref_fixed','float', 91.188)
961 self.add_line('muF2_ref_fixed', 'float', 91.188)
962 self.add_line('QES_ref_fixed', 'float', 91.188)
963 self.add_line('muR_over_ref', 'float', 1.0)
964 self.add_line('muF1_over_ref', 'float', 1.0)
965 self.add_line('muF2_over_ref', 'float', 1.0)
966 self.add_line('QES_over_ref', 'float', 1.0)
967
968 self.add_line('reweight_scale', 'bool', True, fortran_name='do_rwgt_scale')
969 self.add_line('rw_Rscale_up', 'float', 2.0)
970 self.add_line('rw_Rscale_down', 'float', 0.5)
971 self.add_line('rw_Fscale_up', 'float', 2.0)
972 self.add_line('rw_Fscale_down', 'float', 0.5)
973 self.add_line('reweight_PDF', 'bool', True, fortran_name='do_rwgt_pdf')
974 self.add_line('PDF_set_min', 'int', 21101)
975 self.add_line('PDF_set_max', 'int', 21140)
976 self.add_line('iappl', 'int', 0)
977
978 self.add_line('ickkw', 'int', 0)
979 self.add_line('jetalgo', 'float', 1.0)
980
981 self.add_line('lpp1', 'int', 1, fortran_name='lpp(1)')
982 self.add_line('lpp2', 'int', 1, fortran_name='lpp(2)')
983 self.add_line('ebeam1', 'float', 4000, fortran_name='ebeam(1)')
984 self.add_line('ebeam2', 'float', 4000, fortran_name='ebeam(2)')
985
986 self.add_line('bwcutoff', 'float', 15.0)
987
988 self.add_line('ptgmin', 'float', 10.0)
989 self.add_line('etagamma', 'float', -1.0)
990 self.add_line('R0gamma', 'float', 0.4)
991 self.add_line('xn', 'float', 1.0)
992 self.add_line('epsgamma', 'float', 1.0)
993 self.add_line('isoEM', 'bool', True)
994
995 self.add_line('pdlabel','str','cteq6_m')
996
997 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']
998 if self['pdlabel'] not in possible_set:
999 raise InvalidRunCard, 'Invalid PDF set (argument of pdlabel) possible choice are:\n %s' % ','.join(possible_set)
1000
1001
1002
1003 if self['pdlabel'] == 'lhapdf':
1004 self.add_line('lhaid', 'int', 21100)
1005 else:
1006 self.add_line('lhaid', 'int', 21100, log=10)
1007
1008 self.fsock.close()
1009
1011 """Basic Proccard object"""
1012
1013 history_header = \
1014 '#************************************************************\n' + \
1015 '#* MadGraph5_aMC@NLO *\n' + \
1016 '#* *\n' + \
1017 "#* * * *\n" + \
1018 "#* * * * * *\n" + \
1019 "#* * * * * 5 * * * * *\n" + \
1020 "#* * * * * *\n" + \
1021 "#* * * *\n" + \
1022 "#* *\n" + \
1023 "#* *\n" + \
1024 "%(info_line)s" +\
1025 "#* *\n" + \
1026 "#* The MadGraph5_aMC@NLO Development Team - Find us at *\n" + \
1027 "#* https://server06.fynu.ucl.ac.be/projects/madgraph *\n" + \
1028 '#* *\n' + \
1029 '#************************************************************\n' + \
1030 '#* *\n' + \
1031 '#* Command File for MadGraph5_aMC@NLO *\n' + \
1032 '#* *\n' + \
1033 '#* run as ./bin/mg5_aMC filename *\n' + \
1034 '#* *\n' + \
1035 '#************************************************************\n'
1036
1037
1038
1039
1041 """ initialize a basic proc_card"""
1042 self.info = {'model': 'sm', 'generate':None,
1043 'full_model_line':'import model sm'}
1044 list.__init__(self)
1045 if init:
1046 self.read(init)
1047
1048
1049 - def read(self, init):
1050 """read the proc_card and save the information"""
1051
1052 if isinstance(init, str):
1053 init = file(init, 'r')
1054
1055 store_line = ''
1056 for line in init:
1057 line = line.strip()
1058 if line.endswith('\\'):
1059 store_line += line[:-1]
1060 else:
1061 self.append(store_line + line)
1062 store_line = ""
1063 if store_line:
1064 raise Exception, "WRONG CARD FORMAT"
1066 """move an element to the last history."""
1067 for line in self[:]:
1068 if line.startswith(cmd):
1069 self.remove(line)
1070 list.append(self, line)
1071
1073 """"add a line in the proc_card perform automatically cleaning"""
1074
1075 line = line.strip()
1076 cmds = line.split()
1077 if len(cmds) == 0:
1078 return
1079
1080 list.append(self, line)
1081
1082
1083 cmd = cmds[0]
1084
1085 if cmd == 'output':
1086
1087 self.clean(allow_for_removal = ['output'], keep_switch=True,
1088 remove_bef_last='output')
1089 elif cmd == 'generate':
1090
1091 self.clean(remove_bef_last='generate', keep_switch=True,
1092 allow_for_removal= ['generate', 'add process', 'output'])
1093 self.info['generate'] = ' '.join(cmds[1:])
1094 elif cmd == 'add' and cmds[1] == 'process' and not self.info['generate']:
1095 self.info['generate'] = ' '.join(cmds[2:])
1096 elif cmd == 'import':
1097 if len(cmds) < 2:
1098 return
1099 if cmds[1].startswith('model'):
1100 self.info['full_model_line'] = line
1101 self.clean(remove_bef_last='import', keep_switch=True,
1102 allow_for_removal=['generate', 'add process', 'add model', 'output'])
1103 if cmds[1] == 'model':
1104 self.info['model'] = cmds[2]
1105 else:
1106 self.info['model'] = None
1107 elif cmds[1] == 'proc_v4':
1108
1109 self[:] = []
1110
1111
1112 - def clean(self, to_keep=['set','add','load'],
1113 remove_bef_last=None,
1114 to_remove=['open','display','launch', 'check','history'],
1115 allow_for_removal=None,
1116 keep_switch=False):
1117 """Remove command in arguments from history.
1118 All command before the last occurrence of 'remove_bef_last'
1119 (including it) will be removed (but if another options tells the opposite).
1120 'to_keep' is a set of line to always keep.
1121 'to_remove' is a set of line to always remove (don't care about remove_bef_
1122 status but keep_switch acts.).
1123 if 'allow_for_removal' is define only the command in that list can be
1124 remove of the history for older command that remove_bef_lb1. all parameter
1125 present in to_remove are always remove even if they are not part of this
1126 list.
1127 keep_switch force to keep the statement remove_bef_??? which changes starts
1128 the removal mode.
1129 """
1130
1131
1132 if __debug__ and allow_for_removal:
1133 for arg in to_keep:
1134 assert arg not in allow_for_removal
1135
1136
1137 nline = -1
1138 removal = False
1139
1140 while nline > -len(self):
1141 switch = False
1142
1143
1144 if not removal and remove_bef_last:
1145 if self[nline].startswith(remove_bef_last):
1146 removal = True
1147 switch = True
1148
1149
1150 if switch and keep_switch:
1151 nline -= 1
1152 continue
1153
1154
1155 if any([self[nline].startswith(arg) for arg in to_remove]):
1156 self.pop(nline)
1157 continue
1158
1159
1160 if removal:
1161 if allow_for_removal:
1162
1163 if any([self[nline].startswith(arg)
1164 for arg in allow_for_removal]):
1165 self.pop(nline)
1166 continue
1167 elif not any([self[nline].startswith(arg) for arg in to_keep]):
1168
1169 self.pop(nline)
1170 continue
1171
1172
1173 nline -= 1
1174
1182
1184 """write the proc_card to a given path"""
1185
1186 fsock = open(path, 'w')
1187 fsock.write(self.history_header)
1188 for line in self:
1189 while len(line) > 70:
1190 sub, line = line[:70]+"\\" , line[70:]
1191 fsock.write(sub+"\n")
1192 else:
1193 fsock.write(line+"\n")
1194