ATLAS Offline Software
Functions | Variables
python.algorithms.postprocessors.lhe_nominal_weight_updater Namespace Reference

Functions

def lhe_nominal_weight_updater (powheg_LHE_output)
 

Variables

 logger = Logging.logging.getLogger("PowhegControl")
 Get handle to Athena logging. More...
 

Function Documentation

◆ lhe_nominal_weight_updater()

def python.algorithms.postprocessors.lhe_nominal_weight_updater.lhe_nominal_weight_updater (   powheg_LHE_output)
Post-process LHE file to update the nominal weight.
In some cases (namely when for_reweighting == 1), virtual corrections
are added only in the reweighting stage. In this case, the nominal weight
in the <event> block, i.e. in the XWGTUP field, is unfortunately not updated.
This can be a problem later on because Pythia8 uses this weight as nominal,
while the 0th weight in the <rwgt> block is the 'correct' nominal, i.e.
which includes these virtual corrections.
This post-processor will replace the value in the XWGTUP field
by this 0th weight. In addition, the original XWGTUP value is saved as an additional
weight in the <rwgt> block, in a weight with name 'XWGTUP_original',
with an id equal to 9001 and in a group or weights
called 'supplemental'.

#@param powheg_LHE_output  Name of LHE file produced by PowhegBox.

@author Timothee Theveneaux-Pelzer <tpelzer@cern.ch>
#

Definition at line 13 of file lhe_nominal_weight_updater.py.

13 def lhe_nominal_weight_updater(powheg_LHE_output):
14  """Post-process LHE file to update the nominal weight.
15  In some cases (namely when for_reweighting == 1), virtual corrections
16  are added only in the reweighting stage. In this case, the nominal weight
17  in the <event> block, i.e. in the XWGTUP field, is unfortunately not updated.
18  This can be a problem later on because Pythia8 uses this weight as nominal,
19  while the 0th weight in the <rwgt> block is the 'correct' nominal, i.e.
20  which includes these virtual corrections.
21  This post-processor will replace the value in the XWGTUP field
22  by this 0th weight. In addition, the original XWGTUP value is saved as an additional
23  weight in the <rwgt> block, in a weight with name 'XWGTUP_original',
24  with an id equal to 9001 and in a group or weights
25  called 'supplemental'.
26 
27  #@param powheg_LHE_output Name of LHE file produced by PowhegBox.
28 
29  @author Timothee Theveneaux-Pelzer <tpelzer@cern.ch>
30  #"""
31 
32  logger.info("Updating XWGTUP value in lhe file with weight of index 0")
33 
34  wgtid_for_old_XWGTUP_value = 9001 # if not set to None, the old value of XWGTUP will be saved
35  weightgroup_name_for_old_XWGTUP_value = "supplemental"
36  weight_name_for_old_XWGTUP_value = "XWGTUP_original"
37 
38  # Get opening and closing strings
39  preamble = LHE.preamble(powheg_LHE_output)
40  if (wgtid_for_old_XWGTUP_value is not None and
41  weightgroup_name_for_old_XWGTUP_value is not None and
42  weight_name_for_old_XWGTUP_value is not None):
43  # first modify the header, to add the additional weight
44  header_old_str = LHE.header_block(powheg_LHE_output)
45  header_new = LHE.add_weight_to_header(header_old_str, weightgroup_name_for_old_XWGTUP_value, weight_name_for_old_XWGTUP_value, wgtid_for_old_XWGTUP_value)
46  header_new_str = str(ElementTree.tostring(header_new)).replace("\"", "\'").strip() + "\n"
47  # some complicated loop to restore order of original lines
48  header_lines = []
49  for l in header_new_str.splitlines():
50  if l.find("<weightgroup") >= 0:
51  ll = l.strip(">").split()
52  combine = ""
53  name = ""
54  for word in ll:
55  if word.find("combine") >= 0:
56  combine = word.split("combine='")[1].split("'")[0]
57  elif word.find("name") >= 0:
58  name = word.split("name='")[1].split("'")[0]
59  l_formated = "<weightgroup name='%s' combine='%s' >"%(name, combine)
60  header_lines.append(l_formated)
61  else:
62  header_lines.append(l)
63  header_new_str = "\n".join(header_lines)+"\n"
64  # then loop on the preamble lines and write the new preamble
65  preamble_new = ""
66  inHeader = False
67  for input_line in preamble.splitlines():
68  if inHeader: # in header
69  if input_line.find("</header>") >=0:
70  preamble_new += header_new_str # write the new header
71  inHeader = False # next line is out of header
72  else:
73  continue # nothing to do if outside the header
74  else: # not in header
75  if input_line.find("<header>") >=0:
76  inHeader = True # header starts
77  else:
78  preamble_new += input_line + "\n" # not in header, writing the line unmodified
79  preamble = preamble_new # update preamble
80  postamble = LHE.postamble(powheg_LHE_output) # postamble is unmodified
81 
82  powheg_LHE_updated = "{}.updated".format(powheg_LHE_output)
83  with open(powheg_LHE_updated, "w") as f_output:
84  f_output.write("{}".format(preamble))
85  for input_event in LHE.event_iterator(powheg_LHE_output):
86  output_event = LHE.update_XWGTUP_with_reweighted_nominal(input_event, wgtid_for_old_XWGTUP_value)
87  f_output.write(output_event)
88  f_output.write(postamble)
89 
90  # Make a backup of the original events
91  shutil.move(powheg_LHE_output, "{}.lhe_nominal_weight_updater_backup".format(powheg_LHE_output))
92  shutil.move(powheg_LHE_updated, powheg_LHE_output)

Variable Documentation

◆ logger

python.algorithms.postprocessors.lhe_nominal_weight_updater.logger = Logging.logging.getLogger("PowhegControl")

Get handle to Athena logging.

Definition at line 10 of file lhe_nominal_weight_updater.py.

replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
vtune_athena.format
format
Definition: vtune_athena.py:14
python.algorithms.postprocessors.lhe_nominal_weight_updater.lhe_nominal_weight_updater
def lhe_nominal_weight_updater(powheg_LHE_output)
Definition: lhe_nominal_weight_updater.py:13
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
Trk::open
@ open
Definition: BinningType.h:40
str
Definition: BTagTrackIpAccessor.cxx:11
Trk::split
@ split
Definition: LayerMaterialProperties.h:38