-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpwhgreweight.f
1348 lines (1259 loc) · 43.4 KB
/
pwhgreweight.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
subroutine pwhgnewweight(iunin,iunrwgt)
implicit none
integer iunin,iunrwgt
character * 500 stringin
integer iret
include 'nlegborn.h'
include 'pwhg_flst.h'
include 'pwhg_rad.h'
include 'pwhg_flg.h'
include 'pwhg_st.h'
include 'pwhg_pdf.h'
include 'LesHouches.h'
integer maxev
integer k
integer gen_seed,gen_n1,gen_n2
common/cgenrand/gen_seed,gen_n1,gen_n2
real * 8 newweight
logical pwhg_isfinite
external pwhg_isfinite
character * 3 whichpdfpk
character * 200 string
real * 8 powheginput
external powheginput
call lhefreadevlhrwgt(iunin,iunrwgt,iret,stringin)
if(iret.lt.0) then
write(*,*) ' End of event file! Aborting ...'
call exit(-1)
endif
call setrandom(gen_seed,gen_n1,gen_n2)
if(rad_type.eq.1) then
call gen_btilderw
newweight=rad_btilde_arr(rad_ubornidx)*
1 rad_btilde_sign(rad_ubornidx)
if(flg_fullrwgt) then
call fullrwgt(newweight)
endif
elseif(rad_type.eq.2) then
call gen_sigremnantrw
newweight=rad_damp_rem_arr(rad_realalr)
elseif(rad_type.eq.3) then
call gen_sigremnantrw
newweight=rad_reg_arr(rad_realreg)
else
write(*,*) 'Error in pwhgnewweight, invalid rad_type: ',
$ rad_type
call exit(-1)
endif
if(.not.pwhg_isfinite(newweight)) newweight=0d0
write(string,*) '#new weight,renfact,facfact,pdf1,pdf2',
1 xwgtup*newweight/rad_currentweight,st_renfact,
2 st_facfact,pdf_ndns1,pdf_ndns2,' ',whichpdfpk()
call pwhg_io_write(iunrwgt,trim(adjustl(string)))
c write(iunrwgt,'(a)') trim(adjustl(string))
if(adjustl(stringin).eq.'<rwgt>') then
call pwhg_io_write(iunrwgt,trim(adjustl(stringin)))
c write(iunrwgt,'(a)') trim(stringin)
do k=1,1000000
call pwhg_io_read(iunin,stringin,iret)
if(iret /= 0) goto 999
c read(unit=iunin,fmt='(a)',end=999,err=999) stringin
if(stringin.ne.'</rwgt>') then
call pwhg_io_write(iunrwgt,trim(stringin))
c write(iunrwgt,'(a)') trim(stringin)
else
call lhrwgt_writeweight
1 (iunrwgt,xwgtup*newweight/rad_currentweight)
call pwhg_io_write(iunrwgt,trim(stringin))
c write(iunrwgt,'(a)') trim(stringin)
return
endif
enddo
else
call pwhg_io_write(iunrwgt,trim(stringin))
c write(iunrwgt,'(a)') trim(stringin)
endif
return
999 continue
write(*,*) 'Did not find </rwgt> after <rwgt>'
write(*,*) 'in Les Houches file. Exiting ...'
call exit(-1)
end
subroutine gen_btilderw
implicit none
include 'nlegborn.h'
include 'pwhg_flst.h'
integer mcalls,icalls
include 'cgengrids.h'
real * 8 xx(ndiminteg)
real * 8 btilde
external btilde
mcalls=0
icalls=0
call gen(btilde,ndiminteg,xgrid,ymax,ymaxrat,xmmm,ifold,2,
# mcalls,icalls,xx)
end
subroutine gen_sigremnantrw
implicit none
include 'nlegborn.h'
include 'pwhg_flst.h'
include 'cgengrids.h'
real * 8 xx(ndiminteg)
integer mcalls,icalls
real * 8 sigremnant
external sigremnant
mcalls=0
icalls=0
call gen(sigremnant,ndiminteg,xgridrm,ymaxrm,ymaxratrm,
1 xmmmrm,ifoldrm,2,mcalls,icalls,xx)
end
subroutine openoutputrw(iunrwgt)
implicit none
include 'pwhg_flg.h'
include 'pwhg_rnd.h'
integer iunrwgt
character * 20 pwgprefix
character * 200 file
integer lprefix,iret
common/cpwgprefix/pwgprefix,lprefix
real * 8 powheginput
logical exist
if(rnd_cwhichseed.ne.'none') then
file=pwgprefix(1:lprefix)//'events-rwgt-'
1 //rnd_cwhichseed//'.lhe'
else
file=pwgprefix(1:lprefix)//'events-rwgt.lhe'
endif
if(powheginput("#clobberlhe").ne.1) then
inquire(file=file,exist=exist)
if(exist) then
write(*,*) 'pwhg_main: error, file ',trim(file),
1 ' exists! will not overwrite, exiting ...'
call exit(-1)
endif
endif
call pwhg_io_open_write(trim(file),iunrwgt,
1 flg_compress_lhe,iret)
if(iret /= 0) then
write(*,*) ' could not open ',trim(file),' for writing'
write(*,*) ' exiting ...'
call exit(-1)
endif
end
c...reads event information from a les houches events file on unit nlf.
subroutine lhefreadevlhrwgt(nlf,nuo,iret,string)
implicit none
integer nlf,nuo,iret
character * 500 string
include 'LesHouches.h'
integer i,j
iret=0
1 continue
string=' '
call pwhg_io_read(nlf,string,iret)
if(iret /= 0) goto 666
c read(nlf,fmt='(a)',err=777,end=666) string
call pwhg_io_write(nuo,trim(string))
c write(nuo,'(a)') trim(string)
if(string.eq.'</LesHouchesEvents>') then
goto 998
endif
if(string(1:6).eq.'<event') then
c on error try next event. The error may be cause by merging
c truncated event files. On EOF return with no event found
call pwhg_io_read(nlf,string,iret)
if(iret /= 0) goto 666
c read(nlf,fmt='(a)',err=777,end=666) string
call pwhg_io_write(nuo,trim(string))
c write(nuo,'(a)') trim(string)
read(string,fmt=*,end=998,err=1)
1 nup,idprup,xwgtup,scalup,aqedup,aqcdup
do i=1,nup
call pwhg_io_read(nlf,string,iret)
if(iret /= 0) goto 666
c read(nlf,'(a)',err=777,end=666) string
call pwhg_io_write(nuo,trim(string))
c write(nuo,'(a)') trim(string)
read(string,fmt=*,end=998,err=1)
1 idup(i),istup(i),mothup(1,i),
& mothup(2,i),icolup(1,i),icolup(2,i),(pup(j,i),j=1,5),
& vtimup(i),spinup(i)
enddo
call lhefreadextrarw(nlf,nuo,iret,string)
c Go on reading, find the end of the weights section
goto 999
else
goto 1
endif
c no event found:
777 continue
write(*,*) "Error in reading"
write(*,*) string
call exit(-1)
666 continue
iret=-1
return
998 continue
print *,"read </LesHouchesEvents>"
iret=-1
nup=0
999 end
subroutine lhefwritetrailernw(iunin,iunout)
implicit none
integer iunin,iunout
character * 500 string
integer iret
1 continue
string=' '
call pwhg_io_read(iunin,string,iret)
if(iret /= 0) goto 998
c read(iunin,fmt='(a)',err=998,end=998) string
call pwhg_io_write(iunout,trim(string))
c write(iunout,'(a)') trim(string)
if(string.eq.'</LesHouchesEvents>') then
goto 998
endif
goto 1
998 continue
end
subroutine lhefreadextrarw(nlf,nou,iret,string)
implicit none
include 'LesHouches.h'
include 'nlegborn.h'
include 'pwhg_flst.h'
include 'pwhg_rad.h'
include 'pwhg_st.h'
include 'pwhg_kn.h'
include 'pwhg_flg.h'
character * 500 string
integer nlf,nou,iret
logical readrw
integer gen_seed,gen_n1,gen_n2
common/cgenrand/gen_seed,gen_n1,gen_n2
readrw = .false.
1 continue
call pwhg_io_read(nlf,string,iret)
if(iret /= 0) goto 998
c read(unit=nlf,fmt='(a)',end=998) string
if(string.eq.'<rwgt>'.or.
1 string.eq.'</event>') then
c Don't write the end event record; first we must output the new weight
return
endif
if(string.eq.'<event>') then
if(.not.readrw) then
write(*,*)
$ 'Error in lhefreadextra, while reading rwg informations'
write(*,*)'Abort run'
call exit(-1)
endif
backspace nlf
return
endif
if(string.eq.'# Start extra-info-previous-event') then
call pwhg_io_write(nou,trim(string))
c write(nou,'(a)') trim(string)
call pwhg_io_read(nlf,string,iret)
c read(nlf,'(a)') string
call pwhg_io_write(nou,trim(string))
c write(nou,'(a)') trim(string)
read(string(3:),*) rad_kinreg
call pwhg_io_read(nlf,string,iret)
c read(nlf,'(a)') string
read(string(3:),*) rad_type
endif
call pwhg_io_write(nou,trim(string))
c write(nou,'(a)') trim(string)
if(flg_newweight) then
c read a string; if it starts with #rwgt, read first rad_type from the
c string, then all other information, depending upon rad_type.
c set readrw to true
string=adjustl(string)
if(string(1:5).eq.'#rwgt') then
string(1:5)=' '
c do things
c print*, 'FOUND'
read(string,*) rad_type
if(rad_type.eq.1) then
c btilde
read(string,*)rad_type,
$ rad_ubornidx,rad_currentweight,
$ gen_seed,gen_n1,gen_n2
elseif(rad_type.eq.2) then
c remnant
read(string,*)rad_type,
$ rad_realalr,rad_currentweight,
$ gen_seed,gen_n1,gen_n2
elseif(rad_type.eq.3) then
c regular
read(string,*)rad_type,
$ rad_realreg,rad_currentweight,
$ gen_seed,gen_n1,gen_n2
else
write(*,*) 'Invalid rad_type in lhefwriteevrw: ',rad_type
call exit(-1)
endif
c if all went ok, set readrw to true
readrw=.true.
endif
endif
goto 1
998 continue
iret=-1
end
c The following are routines for the implementation of the
c Les Houches standard for reweighting
subroutine lhrwgt_writeweight(iun,weight)
implicit none
integer iun
include 'pwhg_lhrwgt.h'
double precision weight
character * 100 string
integer iret
write(string,'(a,e11.5,a)')
1 "<wgt id='"//trim(adjustl(lhrwgt_id))//"'> ",
2 weight,' </wgt>'
call pwhg_io_write(iun,trim(string))
end
subroutine lhrwgt_writeheader(iun)
implicit none
integer iun
include 'pwhg_lhrwgt.h'
character * 200 tmpstring
character * 200 string
integer j,iret
logical written,in_group
c This flag is set to true when the current weight has
c been written out
written = .false.
call pwhg_io_write(iun,'<initrwgt>')
c write(iun,'(a)') '<initrwgt>'
if(lhrwgt_group_name.eq.' ') then
c Write all lines firs
do j=1,lhrwgt_nheader
call pwhg_io_write(iun,trim(lhrwgt_header(j)))
c write(iun,'(a)') trim(lhrwgt_header(j))
enddo
else
c this flag is set to true when we are writing out weights in
c the current group
in_group = .false.
do j=1,lhrwgt_nheader
if(.not.written.and.in_group
1 .and.adjustl(lhrwgt_header(j)).eq.'</weightgroup>')
2 then
write(string,'(a)') "<weight id='"//
1 trim(adjustl(lhrwgt_id))//
2 "'>"//' '//trim(adjustl(lhrwgt_descr))
3 //' </weight>'
call pwhg_io_write(iun,trim(string))
in_group = .false.
written = .true.
endif
call pwhg_io_write(iun,trim(lhrwgt_header(j)))
c write(iun,'(a)') trim(lhrwgt_header(j))
tmpstring = adjustl(lhrwgt_header(j))
if(tmpstring(1:18).eq.'<weightgroup name=') then
tmpstring = tmpstring(19:)
call getquotedstring(tmpstring,tmpstring,iret)
if(tmpstring.eq.lhrwgt_group_name) in_group = .true.
endif
enddo
endif
if(.not.written) then
if(lhrwgt_group_name.ne.' ') then
if(lhrwgt_group_combine.ne.' ') then
write(string,'(a)') "<weightgroup name='"
1 //trim(lhrwgt_group_name)//"' combine='"
1 //trim(lhrwgt_group_combine)//"'>"
call pwhg_io_write(iun,trim(string))
else
write(string,'(a)') "<weightgroup name='"
1 //trim(lhrwgt_group_name)//"'>"
call pwhg_io_write(iun,trim(string))
endif
endif
write(string,'(a)') "<weight id='"//
1 trim(adjustl(lhrwgt_id))//
1 "'>"//' '//trim(adjustl(lhrwgt_descr))//' </weight>'
call pwhg_io_write(iun,trim(string))
if(lhrwgt_group_name.ne.' ') then
call pwhg_io_write(iun,'</weightgroup>')
endif
endif
call pwhg_io_write(iun,'</initrwgt>')
c write(iun,'(a)') '</initrwgt>'
end
subroutine lhrwgt_checkheader
implicit none
include 'pwhg_lhrwgt.h'
character * (lhrwgt_max_header_columns) string
integer j,iret
do j=1,lhrwgt_nheader
string = adjustl(lhrwgt_header(j))
if(string(1:11).eq.'<weight id=') then
call getquotedstring(string(12:),string,iret)
if(string.eq.lhrwgt_id) then
write(*,*) ' lhrwgt_checkheader: ERROR'
write(*,*) ' lhrwgt_id ',trim(string),' already in use'
call exit(-1)
endif
endif
enddo
end
subroutine lhrwgt_readheader_rw(iun)
implicit none
include 'pwhg_lhrwgt.h'
integer iun
character * (lhrwgt_max_header_columns+200) string,string0
integer j,k,iret
do j=1,1000000
call pwhg_io_read(iun,string0,iret)
c read(iun,'(a)') string0
string=adjustl(string0)
if(string.eq.'<initrwgt>') then
lhrwgt_nheader = 0
do k=1,1000000
call pwhg_io_read(iun,string0,iret)
c read(iun,'(a)') string0
string=adjustl(string0)
if(string.ne.'</initrwgt>') then
lhrwgt_nheader = lhrwgt_nheader + 1
if(lhrwgt_nheader.gt.lhrwgt_maxnheader) then
write(*,*) '******** ERROR ******'
write(*,*) ' lhrwgt_readheader_rw: '
write(*,*)
1 ' found too many strings in header'
write(*,*) ' increase lhrwgt_maxnheader'
1 //' in include/pwg_lhrwgt.h'
call exit(-1)
endif
c check that the string fits
if(len(trim(string0)).gt.
1 lhrwgt_max_header_columns) then
write(*,*) '******** ERROR ******'
write(*,*) ' lhrwgt_readheader_rw: '
write(*,*)
1 ' found too long a string in the header'
write(*,*)
1 ' increase lhrwgt_max_header_columns'
1 //' in include/pwg_lhrwgt.h'
call exit(-1)
endif
lhrwgt_header(lhrwgt_nheader) = trim(string0)
else
return
endif
enddo
write(*,*) '******** ERROR ******'
write(*,*) ' lhrwgt_readheader_rw: '
write(*,*) ' didn;t find the end of the header'
call exit(-1)
endif
enddo
write(*,*) '******** ERROR ******'
write(*,*) ' lhrwgt_readheader_rw: '
write(*,*) ' didn;t find the header'
call exit(-1)
end
subroutine lhrwgt_copyheader(iunin,iunout)
implicit none
include 'pwhg_lhrwgt.h'
integer iunin,iunout
character * (400) string,string0
integer j,k,iret
logical written,in_group
do j=1,1000000
call pwhg_io_read(iunin,string0,iret)
if(iret /= 0) goto 999
c read(unit=iunin,fmt='(a)',end=999,err=999) string0
string=adjustl(string0)
if(string.eq.'<initrwgt>') then
call pwhg_io_backspace(iunin)
call lhrwgt_readheader_rw(iunin)
call lhrwgt_checkheader
call lhrwgt_writeheader(iunout)
return
else
call pwhg_io_write(iunout,trim(string0))
c write(iunout,'(a)') trim(string0)
endif
enddo
999 continue
write(*,*) ' ERROR: did not find <initrwgt> in lhe file'
write(*,*) ' Most likely, the initial run did not specify'
write(*,*) ' a rwgt_id line'
call exit(-1)
end
subroutine getreweightinput
implicit none
include 'pwhg_lhrwgt.h'
call powheginputstring("#lhrwgt_group_name",lhrwgt_group_name)
call powheginputstring("#lhrwgt_group_combine",
1 lhrwgt_group_combine)
call powheginputstring("#lhrwgt_id",lhrwgt_id)
call powheginputstring("#lhrwgt_descr",lhrwgt_descr)
end
subroutine printrwghthdr(iun)
implicit none
include 'pwhg_lhrwgt.h'
INTEGER IUN
if(lhrwgt_id.ne.' ') then
c write(iun,'(a)') '<initrwgt>'
call pwhg_io_write(iun,'<initrwgt>')
if(lhrwgt_group_name.ne.' ') then
if(lhrwgt_group_combine.ne.' ') then
call pwhg_io_write(iun,"<weightgroup name='"
1 //trim(lhrwgt_group_name)//"' combine='"
1 //trim(lhrwgt_group_combine)//"'>")
c write(iun,'(a)') "<weightgroup name='"
c 1 //trim(lahrwgt_group_name)//"' combine='"
c 1 //trim(lhrwgt_group_combine)//"'>"
else
call pwhg_io_write(iun,"<weightgroup name='"
1 //trim(lhrwgt_group_name)//"'>")
c write(iun,'(a)') "<weightgroup name='"
c 1 //trim(lhrwgt_group_name)//"'>"
endif
endif
call pwhg_io_write(iun,"<weight id='"//trim(lhrwgt_id)
1 //"'> "//trim(lhrwgt_descr)//" </weight>")
c write(iun,'(a)') "<weight id='"//trim(lhrwgt_id)
c 1 //"'> "//trim(lhrwgt_descr)//" </weight>"
if(lhrwgt_group_name.ne.' ') then
call pwhg_io_write(iun,"</weightgroup>")
c write(iun,'(a)') "</weightgroup>"
endif
call pwhg_io_write(iun,"</initrwgt>")
c write(iun,'(a)') "</initrwgt>"
endif
end
subroutine printrwgtev(nlf,weight)
implicit none
integer nlf
double precision weight
character(len=300) string
include 'pwhg_lhrwgt.h'
write(string,'(a,e16.9,a)')"<wgt id='"//trim(lhrwgt_id)//"'> ",
1 weight,' </wgt>'
call pwhg_io_write(nlf,trim(string))
end
c From here to the end of file are the subroutines needed for full reweighting,
c that also includes the effect of the change in pdf's in the hardest radiation
subroutine readpowheginputinfo(nlf)
c If any information from the current lhe file is desired, get it here.
c In this case, we set the pdf's used for generating the file, that may
c be needed for reweighting.
implicit none
integer nlf
character * 300 string
character * 3 whichpdf
include 'pwhg_pdf.h'
integer iret,j,ndns1,ndns2,lhans1,lhans2
call pwhg_io_rewind(nlf)
do j=1,1000000
call pwhg_io_read(nlf,string,iret)
if(iret /= 0) goto 999
string = adjustl(string)
if(string(1:5) .eq. 'ndns1') then
read(string(6:),*) ndns1
elseif(string(1:5) .eq. 'ndns2') then
read(string(6:),*) ndns2
elseif(string(1:6) .eq. 'lhans1') then
read(string(7:),*) lhans1
elseif(string(1:6) .eq. 'lhans2') then
read(string(7:),*) lhans2
elseif(string(1:12) .eq. 'PDF package:') then
if(adjustl(string(13:)) .eq. 'lha') then
pdf_ndns1lhe = lhans1
pdf_ndns2lhe = lhans1
whichpdf = 'lha'
elseif(adjustl(string(13:)) .eq. 'mlm') then
pdf_ndns1lhe = ndns1
pdf_ndns2lhe = ndns2
whichpdf = 'mlm'
else
write(*,*) ' readpowheginputinfo: cannot identify'
write(*,*) ' psf package ',trim(adjustl(string))
call exit(-1)
endif
call pwhg_io_rewind(nlf)
if(pdf_ndns1lhe .ne. pdf_ndns2lhe) then
write(*,*)
1 ' readpowheginputinfo: got two different pdf sets',
2 ' for the two imcoming hadrons: ',
3 pdf_ndns1lhe, pdf_ndns2lhe
write(*,*) ' cannot handle that! exiting ...'
call exit(-1)
endif
write(*,*)
1 ' readpowheginputinfo: got ',whichpdf,' set ',
1 pdf_ndns1lhe,' from input lhe file: '
return
endif
enddo
999 continue
write(*,*) ' readpowheginputinfo: something wrong reading'
call exit(-1)
end
subroutine fullrwgt(weight)
c This subroutines reweights also the R/B exp[-int R/B] term in the
c Sudakov form factor.
c It needs to now the pdf's used in the original .lhe
c file. These are provided in a powheg.input "pdforig" entry.
c it computes all reweighting factors needed to update the R/B
c and Sudakov form factor (the last one in an approximate way).
implicit none
real * 8 weight
include 'nlegborn.h'
include 'pwhg_kn.h'
include 'pwhg_flst.h'
include 'pwhg_rad.h'
include 'pwhg_flg.h'
include 'pwhg_st.h'
include 'pwhg_pdf.h'
include 'LesHouches.h'
c These are needed to call generipdfpar.
integer iord,ih,iret
real * 8 lam5l
character * 2 scheme
c
real * 8 mu2
integer fl1b,fl2b,fl1r,fl2r
real * 8 pdf(-pdf_nparton:pdf_nparton)
real * 8 lumorig,lum,as,asorig,exponent,exponentorig,
1 lumbornorig,lumborn,lumreal,lumrealorig,q2l,
2 save_st_lambda5MSB,save_st_mufact2,x1r,x2r,fact
real * 8 powheginput,dotp
integer npdforig,npdf
logical ini
data ini/.true./
integer mode
save ini,npdforig,npdf,mode
logical pwhg_isfinite
external pwhg_isfinite
c These variables are the only ones accessed by the contained subroutines
double precision mm,mm2,ym,ptm,q,ptm2,q2,mtm,mtm2,
1 logtaumin,logtaumax,taumin,taumax,taubmin
integer ngauss
parameter (ngauss=16)
double precision xgauss(ngauss),wgauss(ngauss)
double precision shat,z,em,kmom,aslim,ycmmin,ycmmax,
1 alphads
double precision lam5,q2low,q2high
c end variables accessed by the contained subroutines
c two possibilities:
c A) HERWIG style Sudakov
c Radiation factor = Real(kt2)/Born(kt2) * Lumborn(kt2)/Lumborn(q2l) * Delta_Herwig
c The correction factor is
c alpha(kt2)/alpha_old(kt2) * (Lumreal(kt2)/Lumrealold(kt2))/(Lumborn(kt2)/Lumborn_old(kt2))
c Times (Lumborn(kt2)/Lumborn(q2l))/(Lumborn_old(kt2)/Lumborn_old(q2l)) Delta_Herwig/Delta_Herwig_old
c Equals to
c alpha(kt2)/alpha_old(kt2) * (Lumreal(kt2)/Lumreal_old(kt2)) Lumborn_old(q2l)/Lumborn(q2l)
c times Delta_Herwig/Delta_Herwig_old;
c B) Sjostrand style Sudakov
c Radiation factor = Real(kt2)/Born(kt2) * Delta_Sjostrand
c Correction factor:
c alpha(kt2)/alpha_old(kt2) * (Lumreal(kt2)/Lumreal_old(kt2))/(Lumborn(kt2)/Lumborn_old(kt2))
c Times Delta_Sjostrand/Delta_Sjostrand_old
c Equals to
c alpha(kt2)/alpha_old(kt2) * (Lumreal(kt2)/Lumreal_old(kt2)) * (Lumborn_old(kt2)/Lumborn(kt2))
c
if(ini) then
mode = powheginput("#fullrwgtmode")
if(mode.lt.0) mode = 4
if(pdf_ndns1.ne.pdf_ndns2) then
write(*,*) " fullpdfrwgt now works only for identical pdf's"
write(*,*) " for the two beams ! exiting ..."
call exit(-1)
endif
ini = .false.
endif
npdf = pdf_ndns1
npdforig = pdf_ndns1lhe
x1r = pup(4,1)/ebmup(1)
x2r = pup(4,2)/ebmup(2)
fl1b = flst_born(1,rad_ubornidx)
fl2b = flst_born(2,rad_ubornidx)
fl1r = idup(1)
if(fl1r.eq.21) fl1r = 0
fl2r = idup(2)
if(fl2r.eq.21) fl2r = 0
c If it has Born kinematics, it is already reweighted by the standard POWHEG reweighter.
c However, it must be reweighted with the Sudakov form factor for not emitting below the cutoff scale
c Check that it has Born kinematics by requiring the same flavours and same x_1/2 for real and born.
c Reals are written to the LH file with a precision of 1d-9
if(fl1r .eq. fl1b .and. fl2r .eq. fl2b .and.
1 abs((kn_xb1-x1r)/x1r) .lt. 2d-9 .and.
2 abs((kn_xb2-x2r)/x2r) .lt. 2d-9) then
if(mode.eq.4) then
c we must compute the Sudakov form factor at the current scale with current pdf's
mu2=rad_ptsqmin
save_st_lambda5MSB = st_lambda5MSB
save_st_mufact2 = st_mufact2
c Sudakov, Sjostrand kind, exact phase space
call sudakovxxx(mu2,exponent)
c Compute the same for original pdf's
pdf_ndns1 = npdforig
pdf_ndns2 = npdforig
call genericpdfpar(npdforig,ih,lam5l,scheme,iord,iret)
st_lambda5MSB = lam5l
c Sudakov, Sjostrand kind, exact phase space
call sudakovxxx(mu2,exponentorig)
fact = exp(exponent-exponentorig)
if(pwhg_isfinite(fact)) then
weight = weight * fact
endif
c Set parameters affecting pdf's as in the current settings
st_lambda5MSB = save_st_lambda5MSB
st_mufact2 = save_st_mufact2
pdf_ndns1 = npdf
pdf_ndns2 = npdf
call genericpdfpar(npdf,ih,lam5l,scheme,iord,iret)
endif
return
endif
c Set scale equal to boson pt; take real kinematics from LH event;
c the kn_*real variables are undefined during reweighting.
mu2 = pup(1,nup)**2 + pup(2,nup)**2
q2l = dotp(kn_cmpborn(:,3)+kn_cmpborn(:,4),
1 kn_cmpborn(:,3)+kn_cmpborn(:,4))
save_st_mufact2 = st_mufact2
c Compute Born lum for current pdf's
call genericpdfpar(npdf,ih,lam5l,scheme,iord,iret)
if(mode.ne.3.and.mode.ne.4) then
c in these mode, it is assumed that HERWIG style Sudakovs is a good approximation
st_mufact2 = max(pdf_q2min,q2l)
else
c Sjostrand style Sudakov; must supply the ratio of born luminosities computed at kt2
st_mufact2 = max(pdf_q2min,mu2)
call pdfcall(1,kn_xb1,pdf)
lumborn = pdf(fl1b)
call pdfcall(2,kn_xb2,pdf)
lumborn = lumborn * pdf(fl2b)
endif
c Compute Real lum for current pdf's
st_mufact2 = max(pdf_q2min,mu2)
call pdfcall(1,x1r,pdf)
lumreal = pdf(fl1r)
call pdfcall(2,x2r,pdf)
lumreal = lumreal * pdf(fl2r)
c Get as to compute radiation for current pdf's
as = mcalphas(mu2,lam5l)
save_st_lambda5MSB = st_lambda5MSB
st_lambda5MSB = lam5l
if(q2l.gt.mu2) then
if(mode.eq.1) then
c Sudakov MiNLO style (HERWIG kind)
call sudakov_exponent(mu2,q2l,q2l,exponent,.true.,
1 2,.false.)
elseif(mode.eq.2) then
c Sudakov sikmplified (HERWIG kind)
exponent = simplesudakov(lam5l,mu2,q2l)
elseif(mode.eq.3) then
c Sudakov sikmplified (Sjostrand kind)
exponent =
1 simplesudakovx(lam5l,mu2,q2l,kn_xb1,kn_xb2,fl1b,fl2b)
endif
else
exponent = 0
endif
if(mode.eq.4) then
c Sudakov, Sjostrand kind, exact phase space
call sudakovxxx(mu2,exponent)
exponent = exponent/2
endif
c Compute the same for original pdf's
pdf_ndns1 = npdforig
pdf_ndns2 = npdforig
call genericpdfpar(npdforig,ih,lam5l,scheme,iord,iret)
if(mode.ne.3.and.mode.ne.4) then
st_mufact2 = max(pdf_q2min,q2l)
call pdfcall(1,kn_xb1,pdf)
lumbornorig = pdf(fl1b)
call pdfcall(2,kn_xb2,pdf)
lumbornorig = lumbornorig * pdf(fl2b)
else
c Sjostrand style Sudakov; must supply the ratio of luminosities computed at kt2
st_mufact2 = max(pdf_q2min,mu2)
call pdfcall(1,kn_xb1,pdf)
lumbornorig = pdf(fl1b)
call pdfcall(2,kn_xb2,pdf)
lumbornorig = lumbornorig * pdf(fl2b)
endif
st_mufact2 = max(pdf_q2min,mu2)
call pdfcall(1,x1r,pdf)
lumrealorig = pdf(fl1r)
call pdfcall(2,x2r,pdf)
lumrealorig = lumrealorig * pdf(fl2r)
c Get as to compute radiation for original pdf's
asorig = mcalphas(mu2,lam5l)
st_lambda5MSB = lam5l
if(q2l.gt.mu2) then
if(mode.eq.1) then
c Sudakov MiNLO style (HERWIG kind)
call sudakov_exponent(mu2,q2l,q2l,exponentorig,.true.,
1 2,.false.)
elseif(mode.eq.2) then
c Sudakov sikmplified (HERWIG kind)
exponentorig = simplesudakov(lam5l,mu2,q2l)
elseif(mode.eq.3) then
c Sudakov sikmplified (Sjostrand kind)
exponentorig =
1 simplesudakovx(lam5l,mu2,q2l,kn_xb1,kn_xb2,fl1b,fl2b)
endif
else
exponentorig = 0
endif
if(mode.eq.4) then
c Sudakov, Sjostrand kind, exact phase space
call sudakovxxx(mu2,exponentorig)
exponentorig = exponentorig/2
endif
c Set parameters affecting pdf's as in the current settings
st_lambda5MSB = save_st_lambda5MSB
st_mufact2 = save_st_mufact2
pdf_ndns1 = npdf
pdf_ndns2 = npdf
call genericpdfpar(npdf,ih,lam5l,scheme,iord,iret)
c Compute reweighting factor:
fact = as/asorig ! as for radiation updated
if(mode.ne.3.and.mode.ne.4) then
fact = fact * lumbornorig/lumborn ! pdf ratio arising
! from Sudakov form factors
else
fact = fact * lumbornorig/lumborn ! Factor due to R/B in radiation
! this time evaluated at kt2
endif
fact = fact * lumreal/lumrealorig ! new pdf's in radiation
fact = fact * exp(2*(exponent-exponentorig)) ! Sudakov form factors
if(pwhg_isfinite(fact)) then
weight = weight * fact
endif
contains
double precision function
1 simplesudakovx(lam5,q2low,q2high,x1,x2,fl1,fl2)
implicit none
double precision lam5,q2low,q2high,x1,x2
integer fl1,fl2
integer ngauss
parameter (ngauss=16)
double precision xgauss(ngauss),wgauss(ngauss),xxx(2)
integer j,k
c double precision simplesudakovx0,
double precision res
logical ini
data ini/.true./
save ini,xgauss,wgauss
c Setup gaussian weights and points
if(ini) then
call dgset(0d0,1d0,ngauss,xgauss,wgauss)
ini = .false.
endif
res = 0
do j=1,ngauss
xxx(1) = xgauss(j)
do k=1,ngauss
xxx(2) = xgauss(k)
res = res + wgauss(j)*wgauss(k)*
1 simplesudakovx0(lam5,q2low,q2high,x1,x2,fl1,fl2,xxx)
enddo
enddo
simplesudakovx = res
end function simplesudakovx
double precision function
1 simplesudakovx0(lam5,q2low,q2high,x1,x2,fl1,fl2,xxx)
implicit none
double precision lam5,q2low,q2high,x1,x2,xxx(2)
integer fl1,fl2,fl,j
include 'pwhg_math.h'
include 'pwhg_pdf.h'
include 'pwhg_st.h'
real * 8 kt2,x,xjac,lq2,as,eta,xi,ximax,ximin,y,ymax,z,xx
real * 8 fxr(-pdf_nparton:pdf_nparton),
1 fxb(-pdf_nparton:pdf_nparton)
c real * 8 mcalphas
c external mcalphas
xjac = 1
lq2 = log(q2high/q2low)
kt2 = exp(xxx(1)*lq2)*q2low
xjac = xjac * kt2 * lq2
eta = 4*kt2/q2high
simplesudakovx0 = 0
do j=1,2
if(j.eq.1) then
xx = x1
fl = fl1
else
xx = x2
fl = fl2
endif
if((1-xx)**2.gt.eta) then
c define y=sqrt((1-x)^2-eta);
c y d y = (1-x) dx, dx = y dy /(1-x)
c y goes from 0 to sqrt((1-x1)**2-eta). Needs importance sampling
c near the upper bound, and also near the lower bound if x1 is small.
c Take xi = log((y+eta)/(1-y)) as sampling variable xi
ymax = sqrt((1-xx)**2-eta)
ximax = log((ymax+eta)/(1-ymax))
ximin = log(eta)
xi = (ximax-ximin)*xxx(2) + ximin
xjac = xjac*(ximax-ximin)
z=exp(xi)
xjac = xjac * z
y = (z-eta)/(1+z)
xjac = xjac * (1+eta) / (1+z)**2
x = 1 - sqrt( y**2 + eta )
xjac = xjac * y/(1-x)
st_mufact2 = max(pdf_q2min,kt2)
as = mcalphas(kt2,lam5)
call pdfcall(1,xx,fxb)
call pdfcall(1,xx/x,fxr)
simplesudakovx0 = simplesudakovx0 + (
1 ( cf * (1+x**2)/(1-x) * fxr(fl) +
2 tf * (x**2+(1-x)**2) * fxr(0) )/fxb(fl) )
3 * as/(2*pi) /kt2/x *xjac
4 / sqrt(1-eta/(1-x)**2)
endif
enddo
c we divide by two simply because we multiply by 2 in the main program
simplesudakovx0 = - simplesudakovx0 / 2
end function simplesudakovx0
double precision function simplesudakov(lam50,q2low0,q2high0)
implicit none
double precision lam50,q2low0,q2high0
double precision dgauss
lam5 = lam50
q2low = q2low0
q2high = q2high0
simplesudakov = dgauss(simplesudakov0,0d0,1d0,1d-4)
end function simplesudakov
double precision function simplesudakov0(x)
implicit none
include 'nlegborn.h'
include 'pwhg_math.h'
include 'pwhg_st.h'
include 'pwhg_rad.h'
double precision x
double precision dgauss
real * 8 as,lqlow,l,q2
integer nf
lqlow = log(q2high/q2low)
l = x*lqlow
q2 = q2low*exp(l)
as = mcalphas(q2,lam5)