15     return math.sqrt(E*E - Q2)
 
   19         Q = ROOT.gRandom.BreitWigner(mass, width)
 
   24     px = p3_magnitude * math.sin(theta) * math.cos(phi)
 
   25     py = p3_magnitude * math.sin(theta) * math.sin(phi)
 
   26     pz = p3_magnitude * math.cos(theta)
 
   28     return [Energy, px, py, pz]
 
   32     return ROOT.TLorentzVector(px, py, pz, energy)
 
   39     with open(input_filename, 
'r') 
as input_file:
 
   40         with open(output_filename, 
'w') 
as output_file:
 
   41             for line 
in input_file:
 
   43                     if not event 
and '<event>' not in line:
 
   44                         output_file.write(line)
 
   47                     if not event 
and '<event>' in line:
 
   48                         output_file.write(line)
 
   53                     if '<' in line 
or '>' in line:
 
   55                     if line.startswith(
'<mgrwt>') 
or line.startswith(
'</mgrwt>'):
 
   56                         output_file.write(line)
 
   59                     if abs(
int(line.split()[0])) == 24:
 
   65                     if  (abs(
int(line.split()[0])) == abs(
int(meson_id)) 
and abs(
int(line.split()[2])) == 4) 
or (
not findW 
and abs(
int(line.split()[0])) == abs(
int(meson_id)) 
and abs(
int(line.split()[2]))==3 ): 
 
   68                             line_parts = line.split()
 
   69                             line_parts[0] = 
str(
int(line.split()[0]))
 
   74                             momentum_x = 
float(line.split()[6])
 
   75                             momentum_y = 
float(line.split()[7])
 
   76                             momentum_z= 
float(line.split()[8])
 
   77                             Energy = 
float(line.split()[9])
 
   83                     if  ((abs(
int(line.split()[0])) == 13 
or abs(
int(line.split()[0])) ==11) 
and int(line.split()[2])==4) 
or ( 
not findW 
and (abs(
int(line.split()[0])) == 13 
or abs(
int(line.split()[0])) ==11) 
and int(line.split()[2])==3):
 
   85                             E_l = 
float(line.split()[9])
 
   86                             px_l= 
float(line.split()[6])
 
   87                             py_l= 
float(line.split()[7])
 
   88                             pz_l= 
float(line.split()[8])
 
   95                             beta=combined.BoostVector()
 
  101                             combined_B =meson+lep1
 
  103                             meson_massp =meson.M()
 
  106                             theta = math.acos(meson.Pz() / math.sqrt(meson.Px()**2 + meson.Py()**2 + meson.Pz()**2))
 
  108                             phi = math.atan2(meson.Py(), meson.Px())
 
  112                             while (Q2 > meson.E()*meson.E()+meson.Px()**2 + meson.Py()**2 + meson.Pz()**2 
or not (0.3 < math.sqrt(Q2) < 1.5)):
 
  116                             meson_energy = combined_B.E()/2 +((Q2-lep1.M()**2)/(2*combined_B.E()))
 
  120                             meson.SetPxPyPzE(four_momentum[1],four_momentum[2],four_momentum[3],four_momentum[0])
 
  122                             px_lep= combined_B.Px()-meson.Px()
 
  123                             py_lep= combined_B.Py()-meson.Py()
 
  124                             pz_lep= combined_B.Pz()-meson.Pz()
 
  126                             lep1_energy = math.sqrt(px_lep**2+py_lep**2+pz_lep**2+lep1.M()**2)
 
  127                             lep1.SetPxPyPzE(px_lep,py_lep,pz_lep,lep1_energy)
 
  133                             line_parts[9] = 
str(
"{:+.10e}".
format(meson.E()))
 
  134                             line_parts[6] =
str(
"{:+.10e}".
format(meson.Px()))
 
  135                             line_parts[7] =
str(
"{:+.10e}".
format(meson.Py()))
 
  136                             line_parts[8] =
str(
"{:+.10e}".
format(meson.Pz()))
 
  137                             line_parts[10] =
str(
"{:+.10e}".
format(meson.M()))
 
  139                             updated_line = 
'  '.
join(line_parts) + 
'\n'    
  140                             output_file.write(
'      ' +
''.
join(updated_line) )
 
  142                     if  ((abs(
int(line.split()[0])) == 13 
or abs(
int(line.split()[0])) ==11) 
and int(line.split()[2])==4) 
or (
not findW 
and (abs(
int(line.split()[0])) == 13 
or abs(
int(line.split()[0])) ==11) 
and int(line.split()[2])==3):
 
  143                             line_parts_l = line.split()
 
  144                             line_parts_l[9] = 
str(
"{:+.10e}".
format(lep1.E()))
 
  145                             line_parts_l[6] =
str(
"{:+.10e}".
format(lep1.Px()))
 
  146                             line_parts_l[7] =
str(
"{:+.10e}".
format(lep1.Py()))
 
  147                             line_parts_l[8] =
str(
"{:+.10e}".
format(lep1.Pz()))
 
  148                             line_parts_l[10] =
str(
"{:+.10e}".
format(lep1.M()))
 
  150                             updated_line_l = 
'  '.
join(line_parts_l) + 
'\n'    
  151                             output_file.write(
'      ' +
''.
join(updated_line_l) + 
'\n')
 
  155                         output_file.write(line)
 
  159 if __name__ == 
"__main__":
 
  160     print(
"len(sys.argv)", len(sys.argv))
 
  161     if len(sys.argv) !=5:
 
  162         print(
"Usage: python resample_meson.py input_file.lhe output_file.lhe meson_id meson_width")
 
  164         input_file = sys.argv[1]
 
  165         output_file = sys.argv[2]
 
  166         meson_id = sys.argv[3]
 
  167         meson_width = sys.argv[4]