13 import subprocess, os, sys
17 kconf[knobname] = value
20 default_dataset =
'prod_caf_R17-03-01-prod3reco.d_nd_genie_nonswap_fhc_nova_v08_full_v1' 23 parser = argparse.ArgumentParser(description=
'script to make a template configuration file of all tunable GENIE knobs pertaining to the tag release indicated by the SAM definition name used for producing the files')
24 parser.add_argument(
'-d',
'--defname',type=str,default=default_dataset)
25 parser.add_argument(
'--printout', dest=
'printout', action=
'store_true')
26 parser.add_argument(
'--no-printout', dest=
'printout', action=
'store_false')
27 parser.set_defaults(printout=
True)
28 args = parser.parse_args()
31 if default_dataset == args.defname:
32 print '********** NOTE **********' 33 print 'SAM definition being used for generating the config file is' 35 if default_dataset == args.defname:
36 print 'It can be changed with -d command line option.' 41 (stdout, stderr) = subprocess.Popen(
'svn list svn+ssh://p-novaart@cdcvs.fnal.gov/cvs/projects/novaart/pkgs.svn/tags', shell=
True, stdout=subprocess.PIPE).communicate()
42 for tag
in stdout.split(
'\n'):
43 if tag.rstrip(
'/')
in args.defname:
45 found_tag = tag.rstrip(
'/')
48 print 'The tag version indicated by the input SAM definition name is not found.' 53 (stdout, stderr) = subprocess.Popen(
'source /grid/fermiapp/nova/novaart/novasvn/setup/setup_nova.sh -r '+found_tag+
' &>/dev/null;printenv', shell=
True, stdout=subprocess.PIPE).communicate()
57 for line
in stdout.split(
'\n'):
58 if len(line.split(
'=')) >= 2:
59 envdict[line.split(
'=')[0]] = line.split(
'=')[1].rstrip(
'\n')
62 with
open(os.path.join(envdict[
'NUGEN_DIR'],
'source/NuReweight/ReweightLabels.h'))
as fsrc:
64 if 'genie::rew::' in line:
65 if len(line.split(
'=')) >= 2:
66 knoblist.append(line.split(
'=')[0].strip().replace(
'fReweight',
'').replace(
'kReweight',
''))
69 print 'all available knobs:\n',
'='*80
70 for knobname
in knoblist: sys.stdout.write(knobname+
' ')
75 (stdout, stderr) = subprocess.Popen(
'source /grid/fermiapp/nova/novaart/novasvn/setup/setup_nova.sh -r '+found_tag+
' &>/dev/null; samweb2xrootd `samweb list-files "defname: '+args.defname+
' with limit 1"`', shell=
True, stdout=subprocess.PIPE).communicate()
76 tfilepn = stdout.rstrip(
'\n')
78 print 'Opening CAF file:', tfilepn
81 gSystem.Load(
"libCintex.so")
83 gSystem.Load(os.path.join(envdict[
'SRT_PUBLIC_CONTEXT'],
'lib/Linux2.6-GCC-debug/libStandardRecord_dict.so'))
84 gInterpreter.AddIncludePath(envdict[
'SRT_PUBLIC_CONTEXT'])
86 tfile = TFile.Open(tfilepn)
87 recTree = tfile.Get(
'recTree')
90 if entry.rec.mc.nnu <= 0:
continue 91 nknobs = len(entry.rec.mc.nu[0].rwgt.genie)
95 kconf = collections.OrderedDict()
96 for i
in range(0, nknobs):
97 kconf[knoblist[i]] = 1
120 outfilename =
'knob_config.txt' 121 print 'Writing output file to '+outfilename
122 with
open(outfilename,
'w')
as outfile:
123 for k,v
in kconf.items():
124 outfile.write(k+
' '+
str(v)+
'\n')
procfile open("FD_BRL_v0.txt")
def setknob(knobname, value)