ATLAS Offline Software
PowhegControl_ttFCNC_NLO.py
Go to the documentation of this file.
1 #--------------------------------------------------------------
2 # EVGEN configuration
3 #--------------------------------------------------------------
4 evgenConfig.description = 'POWHEG+Pythia8 ttbar production with Powheg hdamp equal 1.5*top mass, A14 tune, ME NNPDF30 NLO, A14 NNPDF23 LO, FCNC Top decays'
5 evgenConfig.keywords = [ 'top', 'ttbar', 'Higgs', 'FCNC' ]
6 evgenConfig.contact = [ 'james.robinson@cern.ch','andrea.helen.knue@cern.ch','onofrio@liverpool.ac.uk','ian.connelly@cern.ch']
7 
8 include('PowhegControl/PowhegControl_tt_Common.py')
9 # Initial settings
10 if hasattr(PowhegConfig, "topdecaymode"):
11  # Use PowhegControl-00-02-XY (and earlier) syntax
12  PowhegConfig.topdecaymode = 22222 # inclusive top decays
13 else:
14  # Use PowhegControl-00-03-XY (and later) syntax
15  PowhegConfig.decay_mode = "t t~ > undecayed"
16  PowhegConfig.MadSpin_enabled = False
17 
18 PowhegConfig.hdamp = 258.75 # 1.5 * mtop
19 DoSingleWeight = False
20 if DoSingleWeight:
21  PowhegConfig.mu_F = 1.0
22  PowhegConfig.mu_R = 1.0
23  PowhegConfig.PDF = 260000
24 else:
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
32 PowhegConfig.nEvents=int(7.0*runArgs.maxEvents)
33 PowhegConfig.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)
41 RCtphi = 0.
42 RCuphi = 0.
43 RCtcphi = 0.
44 RCctphi = 0.
45 
46 # The tqZ,tqg relevant couplings (c,u) x (Vector,Tensor) x (LH,RH)
47 # vector for tqZ
48 RC1utR = 0.
49 RC1utL = 0.
50 RC3utL = 0.
51 RC1ctR = 0.
52 RC1ctL = 0.
53 RC3ctL = 0.
54 
55 # tensor for tqZ and tqgamma
56 RCtW = 0.
57 RCtB = 0.
58 RCuW = 0.
59 RCuB = 0.
60 RCtcW = 0.
61 RCtcB = 0.
62 RCctW = 0.
63 RCctB = 0.
64 
65 
66 if any("HLepF" in JO for JO in runArgs.jobConfig):
67  PowhegConfig.nEvents = int(7.0*runArgs.maxEvents)
68  print PowhegConfig.nEvents
69 else :
70  raise RuntimeError("Event filter not recognised for this job option")
71 
72 #t-c-H or t-u-H
73 istcH = any("Q2cH" in JO for JO in runArgs.jobConfig) or any("Q2cbarH" in JO for JO in runArgs.jobConfig)
74 
75 # Get the DSID
76 thisDSID = runArgs.runNumber
77 # Apply the offset
78 
79 # Temporary fix shift the dsid only if it's not an inclusive H decay sample
80 if thisDSID < 411229 or thisDSID > 411232 :
81  if istcH:
82  thisDSID = thisDSID - 64
83  else:
84  thisDSID = thisDSID - 48
85 
86 model = 'TopFCNC-onlyh' #eventually, change for tqZ, tqphoton, tqgluon
87 madspin_card_rep = 'madspin_card.dat'
88 madspin_in = 'import run.lhe'
89 madspin_rep = 'set ms_dir MadSpin'
90 madspin_seed = runArgs.randomSeed
91 
92 mscard = open(madspin_card_rep,'w')
93 mscard.write("""
94 set Nevents_for_max_weigth 250 # number of events for the estimate of the max. weight (default: 75)
95 set max_weight_ps_point 1000 # number of PS to estimate the maximum for each event (default: 400)
96 set seed %i
97 %s
98 %s
99 define l+ = l+ ta+
100 define l- = l- ta-
101 define All = l+ l- vl vl~ j
102 \n
103 """%(madspin_seed,madspin_in,madspin_rep))
104 
105 
106 wtyp = thisDSID%4
107 # Non inclusive H decay
108 if 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
118 elif 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'
123 else :
124  raise RuntimeError("No W decays are generated please check the job option")
125 
126 ttyp = thisDSID%2
127 if ttyp == 0:
128  t2str = 'decay t~ > w- b~'
129 else:
130  t2str = 'decay t > w+ b'
131 
132 # the tqH part
133 # As last block coding dsids to be used for inclusive H decay
134 if ( (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))
188 else:
189  raise RuntimeError("No good runNumber")
190 
191 mscard.close()
192 
193 coup = {
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 
215 import shutil,os,subprocess
216 
217 paramFileName = 'MadGraph_param_card_ttFCNC_NLO_FixedFCNCBR.dat'
218 paramFileNameN = 'param_card.dat'
219 paramFile = subprocess.Popen(['get_files','-data',paramFileName]).communicate()
220 if not os.access(paramFileName, os.R_OK):
221  print 'ERROR: Could not get param card'
222  raise RuntimeError("parameter card '%s' missing!"%paramFileName)
223 
224 from MadGraphControl.MadGraphUtils import *
225 build_param_card(param_card_old=paramFileName,param_card_new=paramFileNameN,
226  params={'dim6':coup})
227 
228 
229 
230 fin = open('PowhegOTF._1.events','r')
231 fout = open('run.lhe','w')
232 line = fin.readline()
233 while line != "-->\n":
234  fout.write(line)
235  line = fin.readline()
236 fout.write(line)
237 
238 # add the process
239 fout.write('<MG5ProcCard>\n')
240 fout.write('import model /cvmfs/atlas.cern.ch/repo/sw/Generators/madgraph/models/latest/%s\n'%(model))
241 fout.write('generate p p > t t~ [QCD] \n')
242 fout.write('</MG5ProcCard>\n')
243 
244 # add run parameters
245 eline = str(PowhegConfig.nEvents)+' = nevents\n'
246 fout.write('<MGRunCard>\n')
247 fout.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"
248 fout.write(eline)
249 fout.write('50.0 = bwcutoff\n')
250 fout.write('</MGRunCard>\n')
251 
252 # add model parameters
253 fout.write('<slha>\n')
254 shutil.copyfileobj(open(paramFileNameN, 'r'), fout)
255 fout.write('</slha>\n')
256 fout.write('<montecarlomasses>\n')
257 fout.write(' 1 0.330000E+00\n')
258 fout.write(' 2 0.330000E+00\n')
259 fout.write(' 3 0.500000E+00\n')
260 fout.write(' 4 0.150000E+01\n')
261 fout.write(' 5 0.480000E+01\n')
262 fout.write(' 11 0.510999E-03\n')
263 fout.write(' 13 0.105658E+00\n')
264 fout.write(' 15 0.177682E+01\n')
265 fout.write(' 21 0.000000E+00\n')
266 fout.write('</montecarlomasses>\n')
267 
268 # add the events !
269 line = fin.readline()
270 while 'LesHouchesEvents' not in line:
271  fout.write(line)
272  line = fin.readline()
273 fout.write(line)
274 fout.close()
275 
276 
277 
278 # run MadSpin
279 os.system('$MADPATH/MadSpin/madspin < madspin_card.dat')
280 
281 # This is a Powheg job, so expect lhe file to be called PowhegOTF._1.events
282 unzip = subprocess.Popen(['gunzip','run_decayed.lhe.gz'])
283 unzip.wait()
284 os.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
288 with 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 #--------------------------------------------------------------
300 include('Pythia8_i/Pythia8_A14_NNPDF23LO_EvtGen_Common.py')
301 include("Pythia8_i/Pythia8_Powheg_Main31.py")
302 
303 
304 if 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 
310 genSeq.Pythia8.Commands += [ 'POWHEG:pThard = 0' ]
311 genSeq.Pythia8.Commands += [ 'POWHEG:nFinal = 2' ]
312 genSeq.Pythia8.Commands += [ 'POWHEG:pTdef = 2' ]
313 genSeq.Pythia8.Commands += [ 'POWHEG:vetoCount = 3' ]
314 genSeq.Pythia8.Commands += [ 'POWHEG:pTemt = 0' ]
315 genSeq.Pythia8.Commands += [ 'POWHEG:emitted = 0' ]
316 genSeq.Pythia8.Commands += [ 'POWHEG:MPIveto = 0' ]
MadGraphUtils
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
LeptonFilter
Definition: LeptonFilter.py:1
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.Include.include
include
Definition: Include.py:318
Trk::open
@ open
Definition: BinningType.h:40
str
Definition: BTagTrackIpAccessor.cxx:11