MadGraphControl_tt012FxFx.py 9.57 KB
Newer Older
Giovanni Siragusa's avatar
Giovanni Siragusa committed
1
from MadGraphControl.MadGraphUtils import *
Cyril Pascal Becot's avatar
Cyril Pascal Becot committed
2
3
import fileinput
import subprocess
Giovanni Siragusa's avatar
Giovanni Siragusa committed
4
5
6
7
8
9
from AthenaCommon import Logging
JOlog = Logging.logging.getLogger('FxFxJobOption')
JOlog.info(" Loading MadGraphControl file for tt012 FxFx ")

# General settings
nevents       = 5.0*runArgs.maxEvents # 25% efficiency for FxFx matching plus a safety factor
Franziska Iltzsche's avatar
Franziska Iltzsche committed
10
mode          = 0
Giovanni Siragusa's avatar
Giovanni Siragusa committed
11
12
gridpack_dir  = None
gridpack_mode = False
Cyril Pascal Becot's avatar
Cyril Pascal Becot committed
13
14
15
16
17
18

# MG Particle cuts                                                                                                
mllcut=0
# Shower/merging settings                                                                                                
maxjetflavor=5
parton_shower='PYTHIA8'
Giovanni Siragusa's avatar
Giovanni Siragusa committed
19
20
21
22

# DSID dictionary - Will allow expansion into a control file in the future
# key  - DSID
# arg1 - muQ (qCut) for Pythia8 FxFx
Cyril Pascal Becot's avatar
Cyril Pascal Becot committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# arg2 - alphaS values in Pythi8 shower
ttbar_5fl={410452:["70.0","0.118"], # nonallhad 70 - alphaS lower value
           410453:["70.0","0.118"], # dilepton 70 - alphaS lower value
           410454:["70.0","0.118"], # allhadronic 70 - alphaS lower value
           410455:["30.0","0.118"], # nonallhad 30 - alphaS lower value
           410456:["30.0","0.118"], # dilepton 30 - alphaS lower value
           410457:["30.0","0.118"], # allhadronic 30 - alphaS lower value
           410458:["70.0","0.127"], # nonallhad 70 - A14 nominal alphaS value
           410459:["70.0","0.127"], # dilepton 70 - A14 nominal alphaS value
           410460:["70.0","0.127"], # allhadronic 70 - A14 nominal alphaS value
           410461:["30.0","0.127"], # nonallhad 30 - A14 nominal alphaS value
           410462:["30.0","0.127"], # dilepton 30 - A14 nominal alphaS value
           410463:["30.0","0.127"], # allhadronic 30 - A14 nominal alphaS value
           410448:["70.0","0.118"], # nonallhad 70 - alphaS lower value
           410449:["30.0","0.118"]} # nonallhad 30 - alphaS lower value
Giovanni Siragusa's avatar
Giovanni Siragusa committed
38
39

# We can define the madspin decay pattern based on DSID
Cyril Pascal Becot's avatar
Cyril Pascal Becot committed
40
41
42
nonallhad = [410452, 410455, 410458, 410461, 410448, 410449]
dilepton  = [410453, 410456, 410459, 410462]
allhad    = [410454, 410457, 410460, 410463]
Giovanni Siragusa's avatar
Giovanni Siragusa committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

# Using gridpacks, so make sure there is a check on the config file
if hasattr(runArgs,'inputGenConfFile'):
    evgenConfig.inputconfcheck = "tt012_FxFx"

if runArgs.runNumber in ttbar_5fl:
    name          = 'ttbarjets'
    process       = "pp>tt"
    gridpack_mode = True
    gridpack_dir  = 'madevent/'

else:
    raise RuntimeError("runNumber %i not recognised in these jobOptions."%runArgs.runNumber)

msdecay   = ""
nleptons  = -2

Cyril Pascal Becot's avatar
Cyril Pascal Becot committed
60
if runArgs.runNumber in nonallhad:
Giovanni Siragusa's avatar
Giovanni Siragusa committed
61
    nleptons = -1
Cyril Pascal Becot's avatar
Cyril Pascal Becot committed
62
    nevents  = 4.0*nevents # Filter efficiency
Giovanni Siragusa's avatar
Giovanni Siragusa committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
    msdecay  = "decay t > w+ b, w+ > all all \ndecay t~ > w- b~, w- > all all"
elif runArgs.runNumber in dilepton:
    nleptons = 2
    msdecay  = "define lv = e+ mu+ ta+ ve vm vt e- mu- ta- ve~ vm~ vt~ \ndecay t > w+ b, w+ > lv lv \ndecay t~ > w- b~, w- > lv lv"
elif runArgs.runNumber in allhad:
    nleptons = 0
    msdecay  = "decay t > w+ b, w+ > j j \ndecay t~ > w- b~, w- > j j"
else:
    raise RuntimeError("Do not know which decay is required for this DSID")

JOlog.info(" MadSpin decay defined as "+msdecay)

stringy = 'madgraph.'+str(runArgs.runNumber)+'.MadGraph_'+str(name)

fcard = open('proc_card_mg5.dat','w')
fcard.write("""
import model loop_sm-no_b_mass
define p = p b b~
define j = p
generate p p > t t~ [QCD] @0
add process p p > t t~ j [QCD] @1
add process p p > t t~ j j [QCD] @2
Cyril Pascal Becot's avatar
Cyril Pascal Becot committed
85
output pp_tt_012jFxFx_NLO_13TeV_PY8_MadSpin
Giovanni Siragusa's avatar
Giovanni Siragusa committed
86
87
88
89
90
91
92
93
94
95
""")
fcard.close()

beamEnergy=-999
if hasattr(runArgs,'ecmEnergy'):
    beamEnergy = runArgs.ecmEnergy / 2.
else:
    raise RuntimeError("No center of mass energy found.")


Cyril Pascal Becot's avatar
Cyril Pascal Becot committed
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
lhaid=260000
pdflabel='lhapdf'

#Fetch default LO run_card.dat and set parameters                                                                             
extras = { 'lhaid'         : lhaid,
           'pdlabel'       : "'"+pdflabel+"'",
           'maxjetflavor'  : maxjetflavor,
           'parton_shower' : parton_shower,
           'mll_sf'        : mllcut,
           'mll'           : mllcut}
doSyst=True

if doSyst:
    lhe_version=3
    extras.update({'reweight_scale': '.true.',
                   'rw_Rscale_down':  0.5,
                   'rw_Rscale_up'  :  2.0,
                   'rw_Fscale_down':  0.5,
                   'rw_Fscale_up'  :  2.0,
                   'reweight_PDF'  : '.true.',
                   'PDF_set_min'   : 260001,
                   'PDF_set_max'   : 260100,
                   'ickkw'         :  3,
                   'jetradius'     :  1.0,
                   'ptj'           :  15,
                   'etaj'          :  5,
                   'isoEM'         :'True'})
Giovanni Siragusa's avatar
Giovanni Siragusa committed
123

Cyril Pascal Becot's avatar
Cyril Pascal Becot committed
124
125
126
127
else:
    lhe_version=1
    extras.update({'reweight_scale': '.false.',
                   'reweight_PDF'  : '.false.'})
Giovanni Siragusa's avatar
Giovanni Siragusa committed
128
129


mcjo's avatar
mcjo committed
130
# Location is dependent on the method
Cyril Pascal Becot's avatar
Cyril Pascal Becot committed
131
madspin_card_loc = 'madspin_card.dat'
Giovanni Siragusa's avatar
Giovanni Siragusa committed
132
133
134

if not hasattr(runArgs, 'inputGenConfFile'):
    fMadSpinCard = open('madspin_card.dat','w')
Cyril Pascal Becot's avatar
Cyril Pascal Becot committed
135
    fMadSpinCard.write('import Events/Test/events.lhe.gz\n')
Giovanni Siragusa's avatar
Giovanni Siragusa committed
136
137
138
139
    fMadSpinCard.write('set ms_dir MadSpin\n')
else:
    os.unlink(gridpack_dir+'Cards/madspin_card.dat')
    fMadSpinCard = open(gridpack_dir+'Cards/madspin_card.dat','w')
Cyril Pascal Becot's avatar
Cyril Pascal Becot committed
140
    fMadSpinCard.write('import '+gridpack_dir+'Events/Test/events.lhe.gz\n')
mcjo's avatar
mcjo committed
141
142
143
144
# We cannot use this directory if we wish to use different ME for the decay
# Removing this line will ensure that the MS decay is correct for the process
# and is uncorrelated to the actual gridpack production in this case
#    fMadSpinCard.write('set ms_dir '+gridpack_dir+'MadSpin\n')
Giovanni Siragusa's avatar
Giovanni Siragusa committed
145
146
147
    fMadSpinCard.write('set seed '+str(10000000+int(runArgs.randomSeed))+'\n')
fMadSpinCard.write('''set Nevents_for_max_weigth 250 # number of events for the estimate of the max. weight (default: 75)
set max_weight_ps_point 1000  # number of PS to estimate the maximum for each event (default: 400)
Franziska Iltzsche's avatar
Franziska Iltzsche committed
148
set BW_cut 50
Giovanni Siragusa's avatar
Giovanni Siragusa committed
149
150
151
152
153
%s
launch'''%(msdecay))
fMadSpinCard.close()


Cyril Pascal Becot's avatar
Cyril Pascal Becot committed
154
process_dir = new_process(grid_pack=gridpack_dir)
Giovanni Siragusa's avatar
Giovanni Siragusa committed
155

Cyril Pascal Becot's avatar
Cyril Pascal Becot committed
156
157
158
159
160
161
162
163
164
165
166
build_run_card(run_card_old=get_default_runcard(proc_dir=process_dir),run_card_new='run_card.dat',
               nevts=nevents,rand_seed=runArgs.randomSeed,beamEnergy=beamEnergy,xqcut=0.,
               extras=extras)

get_param_file = subprocess.Popen(['get_files','-data', 'aMcAtNlo_param_card_loop_sm-no_b_mass.dat'])
get_param_file.wait()
import os, shutil
if not os.path.exists('aMcAtNlo_param_card_loop_sm-no_b_mass.dat'):
    raise RuntimeError("Cannot find aMcAtNlo_param_card_loop_sm-no_b_mass.dat")

print_cards()
Giovanni Siragusa's avatar
Giovanni Siragusa committed
167

mcjo's avatar
mcjo committed
168
generate(required_accuracy=0.001,run_card_loc='run_card.dat',param_card_loc='aMcAtNlo_param_card_loop_sm-no_b_mass.dat',proc_dir=process_dir,mode=mode,madspin_card_loc=madspin_card_loc,grid_pack=gridpack_mode,gridpack_dir=gridpack_dir,gridpack_compile=True,random_seed=runArgs.randomSeed,nevents=nevents)
Cyril Pascal Becot's avatar
Cyril Pascal Becot committed
169
outputDS=arrange_output(proc_dir=process_dir,outputDS=stringy+'._00001.events.tar.gz',lhe_version=lhe_version,saveProcDir=True)
Giovanni Siragusa's avatar
Giovanni Siragusa committed
170
171

# Shower
Cyril Pascal Becot's avatar
Cyril Pascal Becot committed
172
evgenConfig.description    = 'aMcAtNlo_ttbar_fxfx control'
Giovanni Siragusa's avatar
Giovanni Siragusa committed
173
174
evgenConfig.contact        = ['francesco.giuli@cern.ch','mcfayden@cern.ch','ian.connelly@cern.ch']
evgenConfig.keywords      += ['ttbar','jets','top']
Cyril Pascal Becot's avatar
Cyril Pascal Becot committed
175
runArgs.inputGeneratorFile=outputDS
Giovanni Siragusa's avatar
Giovanni Siragusa committed
176
177
178
179
180
181

include("MC15JobOptions/Pythia8_A14_NNPDF23LO_EvtGen_Common.py")
include("MC15JobOptions/Pythia8_aMcAtNlo.py")

testSeq.TestHepMC.MaxVtxDisp = 100000000

Cyril Pascal Becot's avatar
Cyril Pascal Becot committed
182
183
184
185
186
187
188
189
190
if 'ATHENA_PROC_NUMBER' in os.environ:
    evgenLog.info('Noticed that you have run with an athena MP-like whole-node setup.  Will re-configure now to make sure that the remainder of the job runs serially.')
    njobs = os.environ.pop('ATHENA_PROC_NUMBER')
    # Try to modify the opts underfoot                                                                                              
    if not hasattr(opts,'nprocs'):
        mglog.warning('Did not see option!')
    else: opts.nprocs = 0
    print opts
    
Giovanni Siragusa's avatar
Giovanni Siragusa committed
191
# Matching settings
Cyril Pascal Becot's avatar
Cyril Pascal Becot committed
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
genSeq.Pythia8.Commands += ["JetMatching:merge           = on",
                            "JetMatching:scheme          = 1",
                            "JetMatching:setMad          = off",
                            "JetMatching:qCut            = "+ttbar_5fl[runArgs.runNumber][0], # Dependent on DSID
                            "JetMatching:coneRadius      = 1.0",
                            "JetMatching:etaJetMax       = 10.0",
                            "JetMatching:doFxFx          = on",
                            "JetMatching:qCutME          = 15.0", # Dependent on DSID
                            "JetMatching:nJetMax         = 2",
                             "SpaceShower:alphaSvalue    = "+ttbar_5fl[runArgs.runNumber][1], # Dependent on DSID
                             "TimeShower:alphaSvalue     = "+ttbar_5fl[runArgs.runNumber][1] # Dependent on DSID
                             ]

# Pythia8_i settings                                                                                                                        
genSeq.Pythia8.UserHook = 'JetMatchingMadgraph'
genSeq.Pythia8.FxFxXS = True
Giovanni Siragusa's avatar
Giovanni Siragusa committed
208
209
210

# Bit more logging info
JOlog.info("JetMatching:qCut   -> "+ttbar_5fl[runArgs.runNumber][0])
Cyril Pascal Becot's avatar
Cyril Pascal Becot committed
211
212
213
214
JOlog.info("SpaceShower:alphaSvalue   -> "+ttbar_5fl[runArgs.runNumber][1])
JOlog.info("TimeShower:alphaSvalue   -> "+ttbar_5fl[runArgs.runNumber][1])
JOlog.info("JetMatching:qCutME -> 15 GeV")
JOlog.info("aMcAtNlo:ptj       -> 15 GeV")
Giovanni Siragusa's avatar
Giovanni Siragusa committed
215
216
217
218
219
220
221
222
223
224
225

# --------------------------------------------------------------
# Apply TTbarWToLeptonFilter
# --------------------------------------------------------------
# Primarily needed for non-all hadronic decays
# nleptons == -2 means inclusive decay ergo no filtering on leptons

if nleptons != -2:
    include("MC15JobOptions/TTbarWToLeptonFilter.py")
    filtSeq.TTbarWToLeptonFilter.NumLeptons = nleptons
    filtSeq.TTbarWToLeptonFilter.Ptcut      = 0.0