A python-only algorithm to monitor Pythia8 behaviour / settings
Definition at line 12 of file Pythia8Util.py.
◆ __init__()
def python.Pythia8Util.Pythia8Util.__init__ |
( |
|
self, |
|
|
|
name = "Pythia8Util" , |
|
|
|
outputParticleDataFile = "ParticleData.local.xml" , |
|
|
|
threshold = 50 |
|
) |
| |
Definition at line 17 of file Pythia8Util.py.
17 def __init__(self, name="Pythia8Util", outputParticleDataFile="ParticleData.local.xml", threshold=50):
18 super(Pythia8Util,self).
__init__(name=name)
19 self.threshold = threshold
23 self.Pythia8Commands = []
24 self.outputParticleDataFile = outputParticleDataFile
◆ cmpparticledata()
def python.Pythia8Util.Pythia8Util.cmpparticledata |
( |
|
self, |
|
|
|
pids, |
|
|
|
rpd |
|
) |
| |
Definition at line 68 of file Pythia8Util.py.
68 def cmpparticledata(self,pids,rpd):
70 f1=self.outputParticleDataFile
71 f2=self.outputParticleDataFile
72 if f1.endswith(
'xml'):
76 doc1 = xml.dom.minidom.parse(f1)
79 self.ensure_toplevel(f1)
81 doc1 = xml.dom.minidom.parse(f1)
83 self.msg.
error(
"Bad file, exiting")
88 doc2 = xml.dom.minidom.parse(f2)
91 self.ensure_toplevel(f2)
93 doc2 = xml.dom.minidom.parse(f2)
95 self.msg.
error(
"Bad file, exiting")
99 particles1 = doc1.getElementsByTagName(
"particle")
100 particles2 = doc2.getElementsByTagName(
"particle")
101 if (particles1.length == particles2.length):
102 self.msg.
info(
"Number of particles before and after Pythia8 initialisation matches ( %d )", particles1.length)
104 self.msg.warning(
"Mismatch in number of particles before and after Pythia8 initialisation. Before: %d , after: %d", particles1.length, particles2.length)
105 for part1
in particles1:
106 if ( part1.getAttribute(
"id")
in pids):
107 for part2
in particles2:
108 if ( part2.getAttribute(
"id") == part1.getAttribute(
"id") ):
109 for attrk2, attrv2
in part2.attributes.items():
111 trypartprop = part2.getAttribute(
"id")+
":"+attrk2
112 if ( trypartprop
in rpd ):
113 requested = rpd[trypartprop]
114 if (
not ( attrk2
in part1.attributes.keys() ) ):
115 self.msg.
info(
"You asked Pythia8 to modify properties for particle %s (%s). Attribute \"%s\" added after initialisation, check it. Requested: %s. After init: %s.", part2.getAttribute(
"name"), part2.getAttribute(
"id"), attrk2, requested, attrv2)
116 for attrk1, attrv1
in part1.attributes.items():
117 if (attrk1 == attrk2
and attrv1 != attrv2):
118 self.msg.warning(
"You asked Pythia8 to modify properties for particle %s (%s). Attribute \"%s\" modified after initialisation. Requested: %s. Before init: %s. After init: %s.", part1.getAttribute(
"name"), part1.getAttribute(
"id"), attrk1, requested, attrv1, attrv2)
◆ cmpsettings()
def python.Pythia8Util.Pythia8Util.cmpsettings |
( |
|
self, |
|
|
|
requestedsettings |
|
) |
| |
Definition at line 44 of file Pythia8Util.py.
44 def cmpsettings(self, requestedsettings):
45 if ( filecmp.cmp(
"Settings_before.log",
"Settings_after.log") ):
46 self.msg.
info(
"Settings match before and after initialisation of Pythia8.")
48 if "PartonShowers:model" in requestedsettings:
49 if (requestedsettings[
"PartonShowers:model"] !=
"1"):
50 self.msg.
info(
"Settings before and after initialisation of Pythia8 don't match, because you asked PartonShowers:model = %s", requestedsettings[
"PartonShowers:model"])
52 self.msg.warning(
"Settings before and after initialisation of Pythia8 don't match.")
53 with open(
"Settings_before.log")
as f1:
54 f1_lines = f1.read().splitlines()
55 with open(
"Settings_after.log")
as f2:
56 f2_lines = f2.read().splitlines()
58 if (len(f1_lines) == len(f2_lines)):
59 for iline
in range(len(f1_lines)):
60 if (f1_lines[iline]!=f2_lines[iline]):
61 if f2_lines[iline].
split(
"=")[0]
in requestedsettings:
62 self.msg.warning(
" >> %s != %s. You requested %s.", f1_lines[iline], f2_lines[iline].
split(
"=")[1], requestedsettings[f2_lines[iline].
split(
"=")[0]])
64 self.msg.
info(
" >> %s != %s", f1_lines[iline], f2_lines[iline].
split(
"=")[1])
66 self.msg.warning(
"Not even the -number- of settings before and after initialisation of Pythia8 matches, check yourself what's going wrong.")
◆ ensure_toplevel()
def python.Pythia8Util.Pythia8Util.ensure_toplevel |
( |
|
self, |
|
|
|
file_name |
|
) |
| |
Insert given string as a new line at the beginning of a file
Definition at line 26 of file Pythia8Util.py.
26 def ensure_toplevel(self,file_name):
27 """ Insert given string as a new line at the beginning of a file """
29 dummy_file = file_name +
'.bak'
31 with open(file_name,
'r')
as read_obj,
open(dummy_file,
'w')
as write_obj:
33 write_obj.write(
"<particledata>"+
'\n')
37 write_obj.write(
"</particledata>"+
' \n')
41 os.rename(dummy_file, file_name)
◆ execute()
def python.Pythia8Util.Pythia8Util.execute |
( |
|
self | ) |
|
◆ finalize()
def python.Pythia8Util.Pythia8Util.finalize |
( |
|
self | ) |
|
Definition at line 129 of file Pythia8Util.py.
131 joparticles = [ i.replace(
" ",
"").
split(
":")[0]
for i
in self.Pythia8Commands
if (i[0].isdigit()) ]
132 requestedparticledata = { i.replace(
" ",
"").
split(
"=")[0]:i.split(
"=")[1].strip()
for i
in self.Pythia8Commands
if (i[0].isdigit()) }
133 requestedsettings = { i.replace(
" ",
"").
split(
"=")[0]:i.split(
"=")[1].strip()
for i
in self.Pythia8Commands
if (
not i[0].isdigit()) }
134 self.cmpsettings(requestedsettings)
135 self.cmpparticledata(joparticles,requestedparticledata)
136 return StatusCode.Success
◆ initialize()
def python.Pythia8Util.Pythia8Util.initialize |
( |
|
self | ) |
|
Definition at line 122 of file Pythia8Util.py.
123 self.msg.
info(
'Running in serial mode.')
124 return StatusCode.Success
◆ mode
python.Pythia8Util.Pythia8Util.mode |
◆ njobs
python.Pythia8Util.Pythia8Util.njobs |
◆ outputParticleDataFile
python.Pythia8Util.Pythia8Util.outputParticleDataFile |
◆ Pythia8Commands
python.Pythia8Util.Pythia8Util.Pythia8Commands |
◆ threshold
python.Pythia8Util.Pythia8Util.threshold |
The documentation for this class was generated from the following file: