ATLAS Offline Software
Loading...
Searching...
No Matches
Herwig7Utils Namespace Reference

Classes

class  ConfigurationCommands
 Class for handling commands to modify the generator configuration. More...
class  Process
 Class for handling a single process. More...
class  ProcessHandler
 Class for handling parallel local multi-processing. More...

Functions

 get_cross_section (run_name, integration_jobs=1)
 Calculate the total cross section from the integration log files.
 get_repeated_pattern (pattern, repetitions)
 Return a string made up of a certain number of repetitions of the same pattern.
 get_size (path)
 Get size of file or folder.
 humanize_bytes (bytes, precision=2)
 Convert file/folder size from bytes to units with appropriate prefixes (multiples of 1000, not 1024!)
 ansi_format (text, colour='None', background_colour='None', bold=False, underline=False, italics=False, marked=False, strikethrough=False)
 Format and colorize terminal output.
 ansi_format_ok (text)
 Green colouring.
 ansi_format_info (text)
 Blue colouring.
 ansi_format_warning (text)
 Yellow colouring.
 ansi_format_error (text)
 Red colouring.

Variables

 athMsgLog = Logging.logging.getLogger('Herwig7Utils')
float integration_grids_precision_threshold = 0.0005

Function Documentation

◆ ansi_format()

Herwig7Utils.ansi_format ( text,
colour = 'None',
background_colour = 'None',
bold = False,
underline = False,
italics = False,
marked = False,
strikethrough = False )

Format and colorize terminal output.

Definition at line 206 of file Herwig7Utils.py.

207 bold=False, underline=False, italics=False, marked=False, strikethrough=False):
208
209 format_none = '\033[0m'
210 format_bold = '\033[1m'
211 format_underline = '\033[4m'
212 format_italics = '\033[3m'
213 format_marked = '\033[7m'
214 format_strikethrough = '\033[9m'
215
216 colours = {
217 'None': '',
218 'Black': '\033[30m',
219 'Grey': '\033[90m',
220 'Red': '\033[91m', 'DarkRed': '\033[31m',
221 'Green': '\033[92m', 'DarkGreen': '\033[32m',
222 'Yellow': '\033[93m', 'Orange': '\033[33m',
223 'Blue': '\033[94m', 'DarkBlue': '\033[34m',
224 'Pink': '\033[95m', 'DarkPink': '\033[35m',
225 'Cyan': '\033[96m', 'DarkCyan': '\033[36m',
226 'White': '\033[97m', 'LightGrey': '\033[37m',
227 }
228
229 background_colours = {
230 'None': '',
231 'Black': '\033[40m',
232 'Red': '\033[41m',
233 'Green': '\033[42m',
234 'Orange': '\033[43m',
235 'Blue': '\033[44m',
236 'Punk': '\033[45m',
237 'Cyan': '\033[46m',
238 'Grey': '\033[47m',
239 }
240
241 if colour in colours:
242 if background_colour in background_colours:
243 return (format_none
244 + colours[colour]
245 + background_colours[background_colour]
246 + (format_bold if bold else '')
247 + (format_underline if underline else '')
248 + (format_italics if italics else '')
249 + (format_marked if marked else '')
250 + (format_strikethrough if strikethrough else '')
251 + text + format_none)
252 else:
253 raise Exception("Could not find background colour '{}'.".format(background_colour))
254 else:
255 raise Exception("Could not find colour '{}'.".format(colour))
256

◆ ansi_format_error()

Herwig7Utils.ansi_format_error ( text)

Red colouring.

Definition at line 270 of file Herwig7Utils.py.

270def ansi_format_error(text):
271 return (ansi_format(text, "Red"))
272

◆ ansi_format_info()

Herwig7Utils.ansi_format_info ( text)

Blue colouring.

Definition at line 262 of file Herwig7Utils.py.

262def ansi_format_info(text):
263 return (ansi_format(text, "Blue"))
264

◆ ansi_format_ok()

Herwig7Utils.ansi_format_ok ( text)

Green colouring.

Definition at line 258 of file Herwig7Utils.py.

258def ansi_format_ok(text):
259 return (ansi_format(text, "Green"))
260

◆ ansi_format_warning()

Herwig7Utils.ansi_format_warning ( text)

Yellow colouring.

Definition at line 266 of file Herwig7Utils.py.

266def ansi_format_warning(text):
267 return (ansi_format(text, "Yellow"))
268

◆ get_cross_section()

Herwig7Utils.get_cross_section ( run_name,
integration_jobs = 1 )

Calculate the total cross section from the integration log files.

Definition at line 107 of file Herwig7Utils.py.

107def get_cross_section(run_name, integration_jobs=1):
108
109 athMsgLog.info("Calculating cross section after integration")
110 logfiles = [run_name+'.integrate'+str(integration_job)+'.log' for integration_job in range(integration_jobs)]
111
112 xsec = 0.0
113 err = 0.0
114
115 for logfile in logfiles:
116
117 athMsgLog.info("- %s", logfile)
118
119
120 with open(logfile, 'r') as log: data = log.read().strip()
121
122 with open(logfile, 'r') as log:
123
124
125 for line in log:
126 if 'Integrate ' in line:
127 n_subprocs = int(line.split('of')[1].replace(':',''))
128 athMsgLog.info(" found %s subprocesses", n_subprocs)
129 break
130
131 data = data.split("Integrate ")[1:]
132
133 for s, subproc in enumerate(data, start=1):
134 _xsec = 0.0
135 _err = 0.0
136 for line in subproc.split("\n"):
137 if 'integrated ( ' in line:
138 _xsec = float(line.split()[2])
139 _err = float(line.split()[4])
140 athMsgLog.info(" - subprocess %s: xsec = %s +/- %s nb", s, _xsec, _err)
141 xsec += _xsec
142 err += _err*_err
143
144 err = math.sqrt(err)
145
146 if err / xsec > integration_grids_precision_threshold:
147 threshold = '{}%'.format(integration_grids_precision_threshold*100.0)
148 if run_name == "Herwig_DEBUG":
149 athMsgLog.warn(ansi_format_warning('! The integration grids only have a low precision (worse than {}): xsec = {} +/- {} nb (accuracy: {:.3f}%)'.format(threshold, xsec, err, err/xsec*100.0)))
150 else:
151 athMsgLog.error(ansi_format_error('! The integration grids only have a low precision (worse than {}): xsec = {} +/- {} nb (accuracy: {:.3f}%)'.format(threshold, xsec, err, err/xsec*100.0)))
152 athMsgLog.warn(ansi_format_warning('! In order to speed up the event generation you should consider improving the statistics of the integration / phase space sampling stage (see the sampler_commands() function).'))
153 else:
154 athMsgLog.info(ansi_format_info('After integration the estimated cross section was found to be: xsec = {} +/- {} nb (accuracy: {:.3f}%)'.format(xsec, err, err/xsec*100.0)))
155
156 return(xsec, err)
157
158
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:310

◆ get_repeated_pattern()

Herwig7Utils.get_repeated_pattern ( pattern,
repetitions )

Return a string made up of a certain number of repetitions of the same pattern.

Definition at line 160 of file Herwig7Utils.py.

160def get_repeated_pattern(pattern, repetitions):
161
162 return(pattern.join(['' for i in range(repetitions+1)]))
163
164

◆ get_size()

Herwig7Utils.get_size ( path)

Get size of file or folder.

Definition at line 166 of file Herwig7Utils.py.

166def get_size(path):
167
168 size = 0
169
170 if os.path.isfile(path):
171 return(os.path.getsize(path))
172
173 elif os.path.isdir(path):
174 for dirpath, dirs, files in os.walk(path):
175 for file in files:
176 file_path = os.path.join(dirpath, file)
177 # if not os.path.islink(file_path): # exclude symlinks because MadGraph has lots of broken symlinks
178 if os.path.isfile(file_path):
179 size += os.path.getsize(file_path)
180
181 return(size)
182
183

◆ humanize_bytes()

Herwig7Utils.humanize_bytes ( bytes,
precision = 2 )

Convert file/folder size from bytes to units with appropriate prefixes (multiples of 1000, not 1024!)

Definition at line 185 of file Herwig7Utils.py.

185def humanize_bytes(bytes, precision=2):
186 # shamelessly stolen from
187 # http://code.activestate.com/recipes/577081-humanized-representation-of-a-number-of-bytes/
188
189 abbrevs = (
190 (1<<50, 'PiB'),
191 (1<<40, 'TiB'),
192 (1<<30, 'GiB'),
193 (1<<20, 'MiB'),
194 (1<<10, 'KiB'),
195 (1, 'byte(s)')
196 )
197 if bytes == 1:
198 return '1 byte'
199 for factor, suffix in abbrevs:
200 if bytes >= factor:
201 break
202 return '%.*f %s' % (precision, bytes / factor, suffix)
203
204

Variable Documentation

◆ athMsgLog

Herwig7Utils.athMsgLog = Logging.logging.getLogger('Herwig7Utils')

Definition at line 10 of file Herwig7Utils.py.

◆ integration_grids_precision_threshold

float Herwig7Utils.integration_grids_precision_threshold = 0.0005

Definition at line 12 of file Herwig7Utils.py.