1
program reweight_xsec_events
2
c Given a LH file that contains an <rwgt> part, computes the scale
3
c and/or PDF dependence through reweighting. A new file is created,
4
c which does not contain the <rwgt> part, but retains only the
5
c information on the maximum and minimum weights due to scale
7
c Compile with makefile_rwgt
9
include "nexternal.inc"
11
include "nFKSconfigs.inc"
12
include "reweight_all.inc"
14
character*7 pdlabel,epa_label
16
common/to_pdf/lhaid,pdlabel,epa_label
17
integer maxevt,ifile,ofile,i,jj,isave,ii
18
double precision saved_weight
20
integer IDBMUP(2),PDFGUP(2),PDFSUP(2),IDWTUP,NPRUP,LPRUP
21
double precision EBMUP(2),XSECUP,XERRUP,XMAXUP
23
PARAMETER (MAXNUP=500)
24
INTEGER NUP,IDPRUP,IDUP(MAXNUP),ISTUP(MAXNUP),
25
# MOTHUP(2,MAXNUP),ICOLUP(2,MAXNUP)
26
DOUBLE PRECISION XWGTUP,SCALUP,AQEDUP,AQCDUP,
27
# PUP(5,MAXNUP),VTIMUP(MAXNUP),SPINUP(MAXNUP)
28
integer isorh_lhe,ifks_lhe,jfks_lhe,fksfather_lhe,ipartner_lhe
29
double precision scale1_lhe,scale2_lhe,percentage
30
integer kwgtinfo,kexternal,jwgtnumpartn
31
double precision wgtcentral,wgtmumin,wgtmumax,wgtpdfmin,wgtpdfmax
32
double precision xmuR_over_ref,xmuF1_over_ref,xmuF2_over_ref,
33
# xQES_over_ref,pr_muR_over_ref,pr_muF1_over_ref,pr_muF2_over_ref,
34
# tmp,yfactR(maxscales),yfactF(maxscales),xsecPDFr(0:maxPDFs)
35
double precision xsecPDFr_acc(0:maxPDFs),xsecScale_acc(maxscales
37
double precision compute_rwgt_wgt_Sev,compute_rwgt_wgt_Sev_nbody
38
& ,compute_rwgt_wgt_Hev
39
integer kr,kf,n,nng,nps,npairs,nsets,izero,itmp,idpdf(0:maxPDFs)
42
character*80 event_file,fname1
44
character*10 MonteCarlo
47
double precision value(20)
49
external compute_rwgt_wgt_Sev,compute_rwgt_wgt_Sev_nbody
50
& ,compute_rwgt_wgt_Hev
52
common/c_addwrite/i_process
54
call setrun !Sets up run parameters
57
write(*,*) 'Enter event file name'
60
write(*,*)'Enter 1 to save all cross sections on tape'
61
write(*,*)' 0 otherwise'
70
xQES_over_ref=QES_over_ref
71
xmuR_over_ref=muR_over_ref
72
xmuF1_over_ref=muF1_over_ref
73
xmuF2_over_ref=muF2_over_ref
75
write(*,*) 'QES_over_ref: ', xQES_over_ref
76
write(*,*) 'muR_over_ref: ', xmuR_over_ref
77
write(*,*) 'muF1_over_ref: ', xmuF1_over_ref
78
write(*,*) 'muF2_over_ref: ', xmuF2_over_ref
79
if (xmuF1_over_ref .ne. xmuF2_over_ref) then
80
write(*,*) "The variables muF1_over_ref and muF2_over_ref" //
81
1 " have to be set equal in the run_card.dat." //
82
1 " Run cannot continue, quitting..."
88
yfactR(2)=rw_Rscale_up
89
yfactR(3)=rw_Rscale_down
91
yfactF(2)=rw_Fscale_up
92
yfactF(3)=rw_Fscale_down
93
write(*,*) 'Doing scale reweight:'
94
write(*,*) rw_Fscale_down, ' < mu_F < ', rw_Fscale_up
95
write(*,*) rw_Rscale_down, ' < mu_R < ', rw_Rscale_up
101
c Note: when ipdf#0, the central PDF set will be used also as a reference
102
c for the scale uncertainty
108
nsets=itmp-idpdf(1)+1
109
write(*,*) 'Doing PDF reweight:'
110
write(*,*) 'Central set id: ', idpdf(0)
111
write(*,*) 'Min error set id: ', idpdf(1)
112
write(*,*) 'Max error set id: ', itmp
113
if(mod(nsets,2).ne.0)then
114
write(*,*)'The number of error sets must be even',nsets
120
idpdf(i)=idpdf(1)+i-1
122
if(nsets.gt.maxPDFs)then
123
write(*,*)'Too many PDFs: increase maxPDFs in reweight0.inc'
129
call pdfset(parm,value)
136
c$$$ call fk88strcat(event_file,'.rwgt',fname1)
137
lef=index(event_file,' ')-1
138
fname1=event_file(1:lef)//'.rwgt'
141
open (unit=ifile,file=event_file,status='old')
144
call read_lhef_header(ifile,maxevt,MonteCarlo)
145
call read_lhef_init(ifile,
146
& IDBMUP,EBMUP,PDFGUP,PDFSUP,IDWTUP,NPRUP,
147
& XSECUP,XERRUP,XMAXUP,LPRUP)
149
do i=1,min(10,maxevt)
150
call read_lhef_event(ifile,
151
& NUP,IDPRUP,XWGTUP,SCALUP,AQEDUP,AQCDUP,
152
& IDUP,ISTUP,MOTHUP,ICOLUP,PUP,VTIMUP,SPINUP,buff)
154
if(buff(1:1).ne.'#')then
155
write(*,*)'This event file cannot be reweighted [1]',i
158
read(buff,*)ch1,iSorH_lhe,ifks_lhe,jfks_lhe,
159
# fksfather_lhe,ipartner_lhe,
160
# scale1_lhe,scale2_lhe,
161
# kwgtinfo,kexternal,jwgtnumpartn,
162
# wgtcentral,wgtmumin,wgtmumax,wgtpdfmin,wgtpdfmax
163
if(kwgtinfo.lt.1.or.kwgtinfo.gt.5)then
164
write(*,*)'This event file cannot be reweighted [2]',i
169
saved_weight=abs(XWGTUP)
171
unweighted=unweighted.and.
172
# abs(1.d0-abs(XWGTUP)/saved_weight).lt.1.d-5
178
write(*,*)'The events appear to be unweighted'
179
write(*,*)' Will store the ratios of recomputed weights'
180
write(*,*)' over reference weights'
182
write(*,*)'The events appear to be weighted'
183
write(*,*)' Will store recomputed weights'
189
open(unit=ofile,file=fname1,status='unknown')
191
call read_lhef_header(ifile,maxevt,MonteCarlo)
192
call write_lhef_header(ofile,maxevt,MonteCarlo)
193
call read_lhef_init(ifile,
194
& IDBMUP,EBMUP,PDFGUP,PDFSUP,IDWTUP,NPRUP,
195
& XSECUP,XERRUP,XMAXUP,LPRUP)
196
call write_lhef_init(ofile,
197
& IDBMUP,EBMUP,PDFGUP,PDFSUP,IDWTUP,NPRUP,
198
& XSECUP,XERRUP,XMAXUP,LPRUP)
202
c To keep track of the accumulated results:
205
xsecScale_acc(jj,ii)=0d0
212
c Determine the flavor map between the NLO and Born
213
call find_iproc_map()
216
call read_lhef_event(ifile,
217
& NUP,IDPRUP,XWGTUP,SCALUP,AQEDUP,AQCDUP,
218
& IDUP,ISTUP,MOTHUP,ICOLUP,PUP,VTIMUP,SPINUP,buff)
219
call reweight_fill_extra_inverse()
221
if(buff(1:1).ne.'#')then
222
write(*,*)'This event file cannot be reweighted [3]',i
225
read(buff,*)ch1,iSorH_lhe,ifks_lhe,jfks_lhe,
226
# fksfather_lhe,ipartner_lhe,
227
# scale1_lhe,scale2_lhe,
228
# kwgtinfo,kexternal,jwgtnumpartn,
229
# wgtcentral,wgtmumin,wgtmumax,wgtpdfmin,wgtpdfmax
230
if(kwgtinfo.lt.1.or.kwgtinfo.gt.5)then
231
write(*,*)'This event file cannot be reweighted [4]',i
235
if(wgtcentral.ne.0.d0.or.wgtmumin.ne.0.d0.or.
236
# wgtmumax.ne.0.d0.or.wgtpdfmin.ne.0.d0.or.
237
# wgtpdfmax.ne.0.d0)then
238
write(*,*)'This event file was already reweighted',i
239
write(*,*)wgtcentral,wgtmumin,wgtmumax,wgtpdfmin,wgtpdfmax
243
if (kwgtinfo.eq.5) call reweight_settozero()
245
if(do_rwgt_scale)then
253
pr_muR_over_ref=xmuR_over_ref*yfactR(kr)
254
pr_muF1_over_ref=xmuF1_over_ref*yfactF(kf)
255
pr_muF2_over_ref=pr_muF1_over_ref
257
if(iSorH_lhe.eq.1)then
258
c The nbody contributions
259
if (kwgtinfo.eq.5) then
260
call fill_reweight0inc_nbody(i_process)
261
wgtxsecmu(kr,kf)=wgtxsecmu(kr,kf)
262
& +compute_rwgt_wgt_Sev_nbody(pr_muR_over_ref
263
& ,pr_muF1_over_ref, pr_muF2_over_ref
264
& ,xQES_over_ref, kwgtinfo)
265
call reweight_settozero()
267
do ii=1,nScontributions
268
nFKSprocess_used=nFKSprocess_reweight(ii)
270
& call fill_reweight0inc(nFKSprocess_used*2-1
272
wgtxsecmu(kr,kf)=wgtxsecmu(kr,kf)+
273
& compute_rwgt_wgt_Sev(pr_muR_over_ref
274
& ,pr_muF1_over_ref, pr_muF2_over_ref
275
& ,xQES_over_ref, kwgtinfo)
276
if (kwgtinfo.eq.5) call reweight_settozero()
278
elseif(iSorH_lhe.eq.2)then
280
& call fill_reweight0inc(nFKSprocess_used*2,
282
wgtxsecmu(kr,kf)=wgtxsecmu(kr,kf)+
283
& compute_rwgt_wgt_Hev(pr_muR_over_ref
284
& ,pr_muF1_over_ref, pr_muF2_over_ref
285
& ,xQES_over_ref, kwgtinfo)
286
if (kwgtinfo.eq.5) call reweight_settozero()
288
write(*,*)'Invalid value of iSorH_lhe',iSorH_lhe
293
if(tmp.lt.wgtmumin)wgtmumin=tmp
294
if(tmp.gt.wgtmumax)wgtmumax=tmp
298
if (kwgtinfo.eq.5) then
299
if (iSorH_lhe.eq.1) then
300
wgtref=wgtref_nbody_all(i_process)
301
do ii=1,nScontributions
302
wgtref=wgtref+ wgtref_all(nFKSprocess_reweight(ii)*2
306
wgtref=wgtref_all(nFKSprocess_used*2,i_process)
311
wgtcentral=wgtxsecmu(1,1)/wgtref
312
wgtmumin=wgtmumin/wgtref
313
wgtmumax=wgtmumax/wgtref
315
wgtcentral=wgtxsecmu(1,1)
327
if(iSorH_lhe.eq.1)then
328
c The nbody contributions
329
if (kwgtinfo.eq.5) then
330
call fill_reweight0inc_nbody(i_process)
331
wgtxsecPDF(n)=wgtxsecPDF(n)
332
$ +compute_rwgt_wgt_Sev_nbody(xmuR_over_ref
333
$ ,xmuF1_over_ref, xmuF2_over_ref ,xQES_over_ref,
335
call reweight_settozero()
337
do ii=1,nScontributions
338
nFKSprocess_used=nFKSprocess_reweight(ii)
340
& call fill_reweight0inc(nFKSprocess_used*2-1
342
wgtxsecPDF(n)=wgtxsecPDF(n)+
343
& compute_rwgt_wgt_Sev(xmuR_over_ref
344
& ,xmuF1_over_ref, xmuF2_over_ref ,xQES_over_ref,
346
if (kwgtinfo.eq.5) call reweight_settozero()
348
elseif(iSorH_lhe.eq.2)then
350
& call fill_reweight0inc(nFKSprocess_used*2,
352
wgtxsecPDF(n)=wgtxsecPDF(n)+
353
& compute_rwgt_wgt_Hev(xmuR_over_ref ,xmuF1_over_ref,
354
& xmuF2_over_ref ,xQES_over_ref, kwgtinfo)
355
if (kwgtinfo.eq.5) call reweight_settozero()
357
write(*,*)'Invalid value of iSorH_lhe',iSorH_lhe
361
if (kwgtinfo.eq.5) then
362
if (iSorH_lhe.eq.1) then
363
wgtref=wgtref_nbody_all(i_process)
364
do ii=1,nScontributions
365
wgtref=wgtref+wgtref_all(nFKSprocess_reweight(ii)
369
wgtref=wgtref_all(nFKSprocess_used*2,i_process)
374
xsecPDFr(n)=wgtxsecPDF(n)/wgtref
376
xsecPDFr(n)=wgtxsecPDF(n)
380
if(do_rwgt_scale)then
381
if(abs(xsecPDFr(0)/wgtcentral-1.d0).gt.1.d-6)then
382
write(*,*)'Central valued computed with mu and PDF differ'
383
write(*,*)xsecPDFr(0),wgtcentral
387
wgtcentral=xsecPDFr(0)
388
c The following serves to write on tape the reference cross section
389
c computed with the new parameters
390
wgtxsecmu(1,1)=wgtxsecPDF(0)
402
# xsecPDFr(0)-xsecPDFr(nps),
403
# xsecPDFr(0)-xsecPDFr(nng)) )**2
406
# xsecPDFr(nps)-xsecPDFr(0),
407
# xsecPDFr(nng)-xsecPDFr(0)) )**2
409
wgtpdfmin=wgtcentral-sqrt(wgtpdfmin)
410
wgtpdfmax=wgtcentral+sqrt(wgtpdfmax)
412
c Restore default PDFs
417
c Keep track of the accumulated results:
418
if (numscales.gt.0) then
421
xsecScale_acc(ii,jj)=xsecScale_acc(ii,jj)+wgtxsecmu(ii
428
xsecPDFr_acc(n)=xsecPDFr_acc(n)+wgtxsecPDF(n)/wgtref
433
c renormalize all the scale & PDF weights to have the same normalization
435
if(do_rwgt_scale)then
438
wgtxsecmu(kr,kf)=wgtxsecmu(kr,kf)/wgtref*XWGTUP
444
wgtxsecPDF(n)=wgtxsecPDF(n)/wgtref*XWGTUP
448
c Write event to disk:
449
write(buff,201)'#aMCatNLO',iSorH_lhe,ifks_lhe,jfks_lhe,
450
# fksfather_lhe,ipartner_lhe,
451
# scale1_lhe,scale2_lhe,
453
# wgtcentral,wgtmumin,wgtmumax,wgtpdfmin,wgtpdfmax
455
call write_lhef_event(ofile,
456
& NUP,IDPRUP,XWGTUP,SCALUP,AQEDUP,AQCDUP,
457
& IDUP,ISTUP,MOTHUP,ICOLUP,PUP,VTIMUP,SPINUP,buff)
461
write(ofile,'(a)')'</LesHouchesEvents>'
465
c Write the accumulated results to a file
466
open (unit=34,file='scale_pdf_dependence.dat',status='unknown')
467
write (34,*) numscales**2
468
if (numscales.gt.0) then
469
write (34,*) ((xsecScale_acc(ii,jj),ii=1,numscales),jj=1
475
write (34,*) nsets + 1
476
write (34,*) (xsecPDFr_acc(n),n=0,nsets)
483
201 format(a9,1x,i1,4(1x,i2),2(1x,e14.8),1x,i1,2(1x,i2),5(1x,e14.8))
489
subroutine set_cms_stuff(icountevts)
495
double precision ybst_til_tolab,ybst_til_tocm,sqrtshat,shat
496
common/parton_cms_stuff/ybst_til_tolab,ybst_til_tocm,
499
double precision sqrtshat_ev,shat_ev
500
common/parton_cms_ev/sqrtshat_ev,shat_ev
502
double precision sqrtshat_cnt(-2:2),shat_cnt(-2:2)
503
common/parton_cms_cnt/sqrtshat_cnt,shat_cnt
505
double precision tau_ev,ycm_ev
506
common/cbjrk12_ev/tau_ev,ycm_ev
508
double precision tau_cnt(-2:2),ycm_cnt(-2:2)
509
common/cbjrk12_cnt/tau_cnt,ycm_cnt
511
double precision xbjrk_ev(2),xbjrk_cnt(2,-2:2)
512
common/cbjorkenx/xbjrk_ev,xbjrk_cnt
514
c rapidity of boost from \tilde{k}_1+\tilde{k}_2 c.m. frame to lab frame --
515
c same for event and counterevents
516
c This is the rapidity that enters in the arguments of the sinh() and
517
c cosh() of the boost, in such a way that
518
c y(k)_lab = y(k)_tilde - ybst_til_tolab
519
c where y(k)_lab and y(k)_tilde are the rapidities computed with a generic
520
c four-momentum k, in the lab frame and in the \tilde{k}_1+\tilde{k}_2
521
c c.m. frame respectively
522
ybst_til_tolab=-ycm_cnt(0)
523
if(icountevts.eq.-100)then
524
c set Bjorken x's in run.inc for the computation of PDFs in auto_dsig
527
c shat=2*k1.k2 -- consistency of this assignment with momenta checked
528
c in phspncheck_nocms
531
c rapidity of boost from \tilde{k}_1+\tilde{k}_2 c.m. frame to
533
ybst_til_tocm=ycm_ev-ycm_cnt(0)
535
c do the same as above for the counterevents
536
xbk(1)=xbjrk_cnt(1,icountevts)
537
xbk(2)=xbjrk_cnt(2,icountevts)
538
shat=shat_cnt(icountevts)
539
sqrtshat=sqrtshat_cnt(icountevts)
540
ybst_til_tocm=ycm_cnt(icountevts)-ycm_cnt(0)