4 import subprocess, os, shlex, re
6 from AthenaCommon
import Logging
9 logger = Logging.logging.getLogger(
"SFGen_i")
23 if hasattr(runArgs,
"ecmEnergy"):
24 self.
rts = runArgs.ecmEnergy
47 if hasattr(runArgs,
"randomSeed"):
48 self.
iseed = runArgs.randomSeed
53 if hasattr(runArgs,
"maxEvents"):
54 self.
nev = runArgs.maxEvents
81 return '.true.' if x
else '.false.'
86 conf+=
"***********************************************************************************\n"
87 conf+=
"***********************************************************************************\n"
88 conf+=
"***********************************************************************************\n"
89 conf+=fortDouble(self.
rts) +
" ! [rts] : CMS collision energy (GeV) \n"
90 conf+=
"***********************************************************************************\n"
91 conf+=
"***********************************************************************************\n"
92 conf+=fortInt(self.
proc) +
" ! [proc] : Process number \n"
93 conf+=fortStr(self.
outtag) +
" ! [outtag] : for output file \n"
94 conf+=fortStr(self.
diff) +
" ! [diff] : elastic ('el'), single/double dissociation ('sd'/'dd') \n"
95 conf+=fortBool(self.
SFerror) +
" ! [SFerror] : Include error from SF input - increases run time \n"
96 conf+=fortBool(self.
mixed) +
" ! [mixed] : include mixed gam/Z + q diagrams \n"
97 conf+=fortBool(self.
Zinit) +
" ! [Zinit] : include Z bosons in initial state \n"
98 conf+=fortBool(self.
subt) +
" ! [subt] : calculate *only* (positive) subtraction term \n"
99 conf+=fortStr(self.
lep1) +
" ! [lep1] : for lepton-lepton scattering (proc=4) \n"
100 conf+=fortStr(self.
lep2) +
" ! [lep2] : for lepton-lepton scattering (proc=4) \n"
101 conf+=fortDouble(self.
kmu) +
" ! [kmu] : = mu(f,r)/mu0 \n"
102 conf+=
"***********************************************************************************\n"
103 conf+=
"************************** To run in collinear mode *****************************\n"
104 conf+=
"***********************************************************************************\n"
105 conf+=fortBool(self.
coll) +
" ! [coll] : use collinear approach + lhapdf \n"
106 conf+=fortStr(self.
PDFname) +
" ! [PDFname] : PDF set \n"
107 conf+=fortInt(self.
PDFmember) +
" ! [PDFmember] : PDF member \n"
108 conf+=
"***********************************************************************************\n"
109 conf+=
"*************Integration parameters************************************************\n"
110 conf+=
"***********************************************************************************\n"
111 conf+=fortInt(self.
ncall) +
" ! [ncall] : Number of calls for preconditioning \n"
112 conf+=fortInt(self.
itmx) +
" ! [itmx] : Number of iterations for preconditioning \n"
113 conf+=fortDouble(self.
prec) +
" ! [prec] : Relative accuracy (in %) in main run \n"
114 conf+=fortInt(self.
ncall1) +
" ! [ncall1] : Number of calls in first iteration \n"
115 conf+=fortInt(self.
inccall) +
" ! [inccall] : Number of increase calls per iteration \n"
116 conf+=fortInt(self.
itend) +
" ! [itend] : Maximum number of iterations \n"
117 conf+=fortInt(self.
iseed) +
" ! [iseed] : Random number seed (integer > 0) \n"
118 conf+=
"***********************************************************************************\n"
119 conf+=
"********************Unweighted events**********************************************\n"
120 conf+=
"***********************************************************************************\n"
121 conf+=fortBool(self.
genunw) +
" ! [genunw] : Generate unweighted events \n"
122 conf+=fortInt(
int(self.
nev)) +
" ! [nev] : Number of events (preferably controlled by maxEvents option in Gen_tf command) \n"
123 conf+=fortStr(self.
erec) +
" ! [erec] : Event record format ('hepmc','lhe','hepevt') \n"
124 conf+=
"***********************************************************************************\n"
125 conf+=
"******************* general cuts ************************************************\n"
126 conf+=
"***********************************************************************************\n"
127 conf+=fortDouble(self.
ymin) +
" ! [ymin] : Minimum dilepton rapidity \n"
128 conf+=fortDouble(self.
ymax) +
" ! [ymax] : Maximum dilepton rapidity \n"
129 conf+=fortDouble(self.
mmin) +
" ! [mmin] : Minimum dilepton mass \n"
130 conf+=fortDouble(self.
mmax) +
" ! [mmax] : Maximum dilepton mass \n"
131 conf+=fortBool(self.
gencuts) +
" ! [gencuts] : Generate cuts below \n"
132 conf+=
"***********************************************************************************\n"
133 conf+=
"********** 2 body final states : p(a) + p(b) **************************************\n"
134 conf+=
"***********************************************************************************\n"
135 conf+=fortDouble(self.
ptamin) +
" ! [ptamin] \n"
136 conf+=fortDouble(self.
ptbmin) +
" ! [ptbmin] \n"
137 conf+=fortDouble(self.
etaamin) +
" ! [etaamin] \n"
138 conf+=fortDouble(self.
etaamax) +
" ! [etaamax] \n"
139 conf+=fortDouble(self.
etabmin) +
" ! [etabmin] \n"
140 conf+=fortDouble(self.
etabmax) +
" ! [etabmax] \n"
141 conf+=fortDouble(self.
ptllmin) +
" ! [ptllmin] \n"
142 conf+=
"***********************************************************************************\n"
143 conf+=
"***********************************************************************************\n"
148 return "evrecs/evrec"+self.
outtag+
".dat"
153 with open(
"input.DAT",
"w")
as outF:
154 outF.write(Init.toFortran())
161 Run a command and print output continuously
163 process = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE, stdin=stdin)
165 output = process.stdout.readline().
decode(
"utf-8")
166 if output ==
'' and process.poll()
is not None:
170 reaesc = re.compile(
r'(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]')
171 text = reaesc.sub(
'', output.strip())
181 logger.info(
"Starting SFGen Initialization")
183 if not os.path.exists(
'evrecs'):
184 os.makedirs(
'evrecs')
185 if not os.path.exists(
'outputs'):
186 os.makedirs(
'outputs')
190 inputDAT =
open(
'input.DAT')
193 raise Exception(
"Problem with file IO; potentially input.DAT not created correctly")
197 rc =
run_command(Init.sfgenpath+
"/bin/SFGen", inputDAT)
200 raise Exception(
"File not found")
203 raise Exception(
"Non-OSError or IOError in execution block")
206 raise Exception(
'Unexpected error in sfgen execution in SFGenInitialize')
214 logger.info(
"Starting SFGen Itself")
216 if not os.path.exists(
'evrecs'):
217 os.makedirs(
'evrecs')
218 if not os.path.exists(
'outputs'):
219 os.makedirs(
'outputs')
223 inputDAT =
open(
'input.DAT')
225 raise Exception (
"Problem with IO; potentially input.DAT not created correctly")
230 rc =
run_command(Init.sfgenpath+
'/bin/SFGen', stdin=inputDAT)
233 raise Exception(
"SFGen executable or file not found")
236 raise Exception(
"Non-OSError or IOError in SFGen execution block")
239 raise Exception(
'Unexpected error in sfgen execution in SFGenExecute')
248 print(Init.toFortran())
251 genSeq.SFGenConfig = Init