Loading [MathJax]/jax/output/SVG/config.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
lhe_cleaner.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaCommon import Logging
4 from ...decorators import timed
5 from ...utility import FileParser
6 
7 
8 logger = Logging.logging.getLogger("PowhegControl")
9 
10 @timed("LHE file cleaning")
11 def lhe_cleaner(powheg_LHE_output):
12  """Post-process LHE file to conform to what the parton-shower generator expects.
13 
14  @param powheg_LHE_output Name of LHE file produced by PowhegBox.
15  """
16  logger.info("Starting to run PowhegControl LHE file cleaner")
17  import os
18  os.system('cp {0} unmodified_{0}'.format(powheg_LHE_output))
19 
20 
28 
29  # Removing rwgt, pdf, and new weight comment lines if one such line looks buggy, i.e. if one NaN values is found
30  # Otherwise it would probably make Pythia crash (even versions which accept such comment lines)
31  pdf_removed = FileParser(powheg_LHE_output).text_remove_all_if_one_line_matches("^#pdf", "NaN")
32  rwg_removed = FileParser(powheg_LHE_output).text_remove_all_if_one_line_matches("^#rwgt", "NaN")
33  new_removed = FileParser(powheg_LHE_output).text_remove_all_if_one_line_matches("^#new weight", "NaN")
34  matching_removed = FileParser(powheg_LHE_output).text_remove_all_if_one_line_matches("^#matching", "NaN")
35  rdm_removed = FileParser(powheg_LHE_output).text_remove_all_if_one_line_matches("^ #Random", "NaN") # this one starts with a space
36 
37  if pdf_removed != 0:
38  logger.info("{} line(s) starting with '#pdf' were removed in {} since at least one looked buggy".format(pdf_removed, powheg_LHE_output))
39  if rwg_removed != 0:
40  logger.info("{} line(s) starting with '#rwgt' were removed in {} since at least one looked buggy".format(rwg_removed, powheg_LHE_output))
41  if new_removed != 0:
42  logger.info("{} line(s) starting with '#new weight' were removed in {} since at least one looked buggy".format(new_removed, powheg_LHE_output))
43  if matching_removed != 0:
44  logger.info("{} line(s) starting with '#matching' were removed in {} since at least one looked buggy".format(matching_removed, powheg_LHE_output))
45  if rdm_removed != 0:
46  logger.info("{} line(s) starting with ' #Random' were removed in {} since at least one looked buggy".format(rdm_removed, powheg_LHE_output)) # this one starts with a space
47 
48  # Correct LHE version identification; otherwise Pythia will treat all files as v1
49  FileParser(powheg_LHE_output).text_replace('LesHouchesEvents version="1.0"', 'LesHouchesEvents version="3.0"')
python.decorators.timed.timed
def timed(name)
Decorator to output function execution time.
Definition: timed.py:12
vtune_athena.format
format
Definition: vtune_athena.py:14
python.algorithms.postprocessors.lhe_cleaner.lhe_cleaner
def lhe_cleaner(powheg_LHE_output)
Definition: lhe_cleaner.py:11