ATLAS Offline Software
Loading...
Searching...
No Matches
PowhegControl_ttFCNC_NLO.py
Go to the documentation of this file.
1#--------------------------------------------------------------
2# EVGEN configuration
3#--------------------------------------------------------------
4evgenConfig.description = 'POWHEG+Pythia8 ttbar production with Powheg hdamp equal 1.5*top mass, A14 tune, ME NNPDF30 NLO, A14 NNPDF23 LO, FCNC Top decays'
5evgenConfig.keywords = [ 'top', 'ttbar', 'Higgs', 'FCNC' ]
6evgenConfig.contact = [ 'james.robinson@cern.ch','andrea.helen.knue@cern.ch','onofrio@liverpool.ac.uk','ian.connelly@cern.ch']
7
8include('PowhegControl/PowhegControl_tt_Common.py')
9# Initial settings
10if hasattr(PowhegConfig, "topdecaymode"):
11 # Use PowhegControl-00-02-XY (and earlier) syntax
12 PowhegConfig.topdecaymode = 22222 # inclusive top decays
13else:
14 # Use PowhegControl-00-03-XY (and later) syntax
15 PowhegConfig.decay_mode = "t t~ > undecayed"
16 PowhegConfig.MadSpin_enabled = False
17
18PowhegConfig.hdamp = 258.75 # 1.5 * mtop
19DoSingleWeight = False
20if DoSingleWeight:
21 PowhegConfig.mu_F = 1.0
22 PowhegConfig.mu_R = 1.0
23 PowhegConfig.PDF = 260000
24else:
25 PowhegConfig.mu_F = [1.0, 2.0, 0.5, 1.0, 1.0, 0.5, 2.0, 0.5, 2.0] # List of factorisation scales which pairs with renormalisation scale below
26 PowhegConfig.mu_R = [1.0, 1.0, 1.0, 2.0, 0.5, 0.5, 2.0, 2.0, 0.5] # List of renormalisation scales
27 PowhegConfig.PDF = [260000, 25200, 13165, 90900] # NNPDF30, MMHT, CT14, PDF4LHC - PDF variations with nominal scale variation
28 PowhegConfig.PDF.extend(range(260001, 260101)) # Include the NNPDF error set
29 PowhegConfig.PDF.extend(range(90901 , 90931 )) # Include the PDF4LHC error set
30
31#PowhegConfig.nEvents *= 1.1 # compensate filter efficiency
32PowhegConfig.nEvents=int(7.0*runArgs.maxEvents)
33PowhegConfig.generate()
34
35#--------------------------------------------------------------
36# Now preparing for MadSpin
37#--------------------------------------------------------------
38
39# The couplings. Only real part.
40# The tqH relevant couplings (c,u) x (LH,RH) (scalar of course)
41RCtphi = 0.
42RCuphi = 0.
43RCtcphi = 0.
44RCctphi = 0.
45
46# The tqZ,tqg relevant couplings (c,u) x (Vector,Tensor) x (LH,RH)
47# vector for tqZ
48RC1utR = 0.
49RC1utL = 0.
50RC3utL = 0.
51RC1ctR = 0.
52RC1ctL = 0.
53RC3ctL = 0.
54
55# tensor for tqZ and tqgamma
56RCtW = 0.
57RCtB = 0.
58RCuW = 0.
59RCuB = 0.
60RCtcW = 0.
61RCtcB = 0.
62RCctW = 0.
63RCctB = 0.
64
65
66if any("HLepF" in JO for JO in runArgs.jobConfig):
67 PowhegConfig.nEvents = int(7.0*runArgs.maxEvents)
68 print PowhegConfig.nEvents
69else :
70 raise RuntimeError("Event filter not recognised for this job option")
71
72#t-c-H or t-u-H
73istcH = any("Q2cH" in JO for JO in runArgs.jobConfig) or any("Q2cbarH" in JO for JO in runArgs.jobConfig)
74
75# Get the DSID
76thisDSID = runArgs.runNumber
77# Apply the offset
78
79# Temporary fix shift the dsid only if it's not an inclusive H decay sample
80if thisDSID < 411229 or thisDSID > 411232 :
81 if istcH:
82 thisDSID = thisDSID - 64
83 else:
84 thisDSID = thisDSID - 48
85
86model = 'TopFCNC-onlyh' #eventually, change for tqZ, tqphoton, tqgluon
87madspin_card_rep = 'madspin_card.dat'
88madspin_in = 'import run.lhe'
89madspin_rep = 'set ms_dir MadSpin'
90madspin_seed = runArgs.randomSeed
91
92mscard = open(madspin_card_rep,'w')
93mscard.write("""
94set Nevents_for_max_weigth 250 # number of events for the estimate of the max. weight (default: 75)
95set max_weight_ps_point 1000 # number of PS to estimate the maximum for each event (default: 400)
96set seed %i
97%s
98%s
99define l+ = l+ ta+
100define l- = l- ta-
101define All = l+ l- vl vl~ j
102\n
103"""%(madspin_seed,madspin_in,madspin_rep))
104
105
106wtyp = thisDSID%4
107# Non inclusive H decay
108if not thisDSID >= 411229 and thisDSID <= 411232 :
109 if wtyp == 0:
110 wstr = ', w- > l- vl~'
111 elif wtyp == 1:
112 wstr = ', w+ > l+ vl'
113 elif wtyp == 2:
114 wstr = ', w- > j j'
115 elif wtyp == 3:
116 wstr = ', w+ > j j'
117# Inclusive H decay dsids
118elif thisDSID >= 411229 and thisDSID <= 411232 :
119 if wtyp == 0 or wtyp == 2:
120 wstr = ', w- > All All'
121 if wtyp == 1 or wtyp == 3:
122 wstr = ', w+ > All All'
123else :
124 raise RuntimeError("No W decays are generated please check the job option")
125
126ttyp = thisDSID%2
127if ttyp == 0:
128 t2str = 'decay t~ > w- b~'
129else:
130 t2str = 'decay t > w+ b'
131
132# the tqH part
133# As last block coding dsids to be used for inclusive H decay
134if ( (thisDSID >= 410700 and thisDSID <= 410779) or (thisDSID >= 410588 and thisDSID <= 410595) or (thisDSID >= 411229 and thisDSID <= 411232 ) ):
135
136 keyName = 'Higgs'
137
138 # Non inclusive H decay
139 if not thisDSID >= 411229 and thisDSID <= 411232 :
140 if thisDSID >= 410592 and thisDSID <= 410595 :
141 theDIDS = thisDSID - 410700 + 104
142 elif thisDSID >= 410588 and thisDSID <= 410591:
143 theDIDS = thisDSID - 410700 + 108
144 else :
145 theDIDS = thisDSID - 410700
146
147 # Shift condition for the inclusive H decay, turn the DSID negative
148 if thisDSID >= 411229 and thisDSID <= 411232 :
149 theDIDS = thisDSID - 411233
150
151 #semi-manually setting the couplings (for the inclusive H decay cases)..
152 # Changed the if conditions after a proper shift is applied, inclusive H decay
153 if theDIDS == -2 or theDIDS == -1 :
154 RCtphi = 1.
155 elif theDIDS == -3 or theDIDS == -4 :
156 RCtcphi = 1.
157 #other channels
158 elif theDIDS >= 0 and theDIDS < 20:
159 RCtcphi = 1.
160 elif theDIDS < 40:
161 RCtphi = 1.
162 elif theDIDS < 60:
163 RCctphi = 1.
164 else:
165 RCuphi = 1.
166
167 # Default for channels other than inclusive H decay
168 qtyp = theDIDS/20
169 if theDIDS >= 40:
170 qtyp = (theDIDS-40)/20
171 #For the inclusive H decay samples, 'theDSID' should be negative only for the inclusive H decay
172 elif theDIDS <= 0:
173 if theDIDS == -2 or theDIDS == -1 :
174 qtyp=1
175 elif theDIDS == -4 or theDIDS == -3 :
176 qtyp=0
177
178 if ttyp%2 == 0 and qtyp == 0:
179 t1str = 'decay t > c h'
180 elif ttyp%2 == 1 and qtyp == 0:
181 t1str = 'decay t~ > c~ h'
182 elif ttyp%2 == 0 and qtyp == 1:
183 t1str = 'decay t > u h'
184 elif ttyp%2 == 1 and qtyp == 1:
185 t1str = 'decay t~ > u~ h'
186
187 mscard.write("""%s\n%s%s\nlaunch"""%(t1str,t2str,wstr))
188else:
189 raise RuntimeError("No good runNumber")
190
191mscard.close()
192
193coup = {
194 'RCtphi' : RCtphi ,
195 'RCuphi' : RCuphi ,
196 'RCtcphi' : RCtcphi,
197 'RCctphi' : RCctphi,
198
199 'RC1utR' : RC1utR,
200 'RC1utL' : RC1utL,
201 'RC3utL' : RC3utL,
202 'RC1ctR' : RC1ctR,
203 'RC1ctL' : RC1ctL,
204 'RC3ctL' : RC3ctL,
205 'RCtW' : RCtW,
206 'RCtB' : RCtB,
207 'RCuW' : RCuW,
208 'RCuB' : RCuB,
209 'RCtcW' : RCtcW,
210 'RCtcB' : RCtcB,
211 'RCctW' : RCctW,
212 'RCctB' : RCctB
213 }
214
215import shutil,os,subprocess
216
217paramFileName = 'MadGraph_param_card_ttFCNC_NLO_FixedFCNCBR.dat'
218paramFileNameN = 'param_card.dat'
219paramFile = subprocess.Popen(['get_files','-data',paramFileName]).communicate()
220if not os.access(paramFileName, os.R_OK):
221 print 'ERROR: Could not get param card'
222 raise RuntimeError("parameter card '%s' missing!"%paramFileName)
223
225build_param_card(param_card_old=paramFileName,param_card_new=paramFileNameN,
226 params={'dim6':coup})
227
228
229
230fin = open('PowhegOTF._1.events','r')
231fout = open('run.lhe','w')
232line = fin.readline()
233while line != "-->\n":
234 fout.write(line)
235 line = fin.readline()
236fout.write(line)
237
238# add the process
239fout.write('<MG5ProcCard>\n')
240fout.write('import model /cvmfs/atlas.cern.ch/repo/sw/Generators/madgraph/models/latest/%s\n'%(model))
241fout.write('generate p p > t t~ [QCD] \n')
242fout.write('</MG5ProcCard>\n')
243
244# add run parameters
245eline = str(PowhegConfig.nEvents)+' = nevents\n'
246fout.write('<MGRunCard>\n')
247fout.write('#0.01 = req_acc_FO\n') #Need because of a new check introduced in 2.5.0 : if not there, RunCardLO will be considered, which wants a line like that "x = nhel ! x = 0,1"
248fout.write(eline)
249fout.write('50.0 = bwcutoff\n')
250fout.write('</MGRunCard>\n')
251
252# add model parameters
253fout.write('<slha>\n')
254shutil.copyfileobj(open(paramFileNameN, 'r'), fout)
255fout.write('</slha>\n')
256fout.write('<montecarlomasses>\n')
257fout.write(' 1 0.330000E+00\n')
258fout.write(' 2 0.330000E+00\n')
259fout.write(' 3 0.500000E+00\n')
260fout.write(' 4 0.150000E+01\n')
261fout.write(' 5 0.480000E+01\n')
262fout.write(' 11 0.510999E-03\n')
263fout.write(' 13 0.105658E+00\n')
264fout.write(' 15 0.177682E+01\n')
265fout.write(' 21 0.000000E+00\n')
266fout.write('</montecarlomasses>\n')
267
268# add the events !
269line = fin.readline()
270while 'LesHouchesEvents' not in line:
271 fout.write(line)
272 line = fin.readline()
273fout.write(line)
274fout.close()
275
276
277
278# run MadSpin
279os.system('$MADPATH/MadSpin/madspin < madspin_card.dat')
280
281# This is a Powheg job, so expect lhe file to be called PowhegOTF._1.events
282unzip = subprocess.Popen(['gunzip','run_decayed.lhe.gz'])
283unzip.wait()
284os.system('cp run_decayed.lhe PowhegOTF._1.events')
285
286# Does MadSpin add some spurious lines that make the weight names unreadable ?
287# see https://bugs.launchpad.net/mg5amcnlo/+bug/1720979
288with open('PowhegOTF._1.events', 'r+') as f:
289 t = f.read()
290 to_delete = [ '<![CDATA[', ']]>' ]
291 f.seek(0)
292 for line in t.split('\n'):
293 if line not in to_delete:
294 f.write(line + '\n')
295 f.truncate()
296
297#--------------------------------------------------------------
298# Pythia8 showering
299#--------------------------------------------------------------
300include('Pythia8_i/Pythia8_A14_NNPDF23LO_EvtGen_Common.py')
301include("Pythia8_i/Pythia8_Powheg_Main31.py")
302
303
304if any("HLepF" in JO for JO in runArgs.jobConfig):
305 if not hasattr(filtSeq,"LeptonFilter"):
306 from GeneratorFilters.GeneratorFiltersConf import LeptonFilter
307 filtSeq += LeptonFilter()
308 filtSeq.LeptonFilter.Ptcut = 15000.0#MeV
309
310genSeq.Pythia8.Commands += [ 'POWHEG:pThard = 0' ]
311genSeq.Pythia8.Commands += [ 'POWHEG:nFinal = 2' ]
312genSeq.Pythia8.Commands += [ 'POWHEG:pTdef = 2' ]
313genSeq.Pythia8.Commands += [ 'POWHEG:vetoCount = 3' ]
314genSeq.Pythia8.Commands += [ 'POWHEG:pTemt = 0' ]
315genSeq.Pythia8.Commands += [ 'POWHEG:emitted = 0' ]
316genSeq.Pythia8.Commands += [ 'POWHEG:MPIveto = 0' ]
Filter events based on presence of charged leptons.