@@ -49,24 +49,61 @@ fn convert_into_applgrid(
4949fn convert_into_fastnlo (
5050 output : & Path ,
5151 grid : & Grid ,
52- conv_funs : & mut [ Pdf ] ,
53- _ : usize ,
52+ fun_names : & ConvFuns ,
53+ scales : usize ,
5454 discard_non_matching_scales : bool ,
5555) -> Result < ( & ' static str , Vec < f64 > , usize , Vec < bool > ) > {
56- // TODO: check also scale-varied results
56+ use pineappl_fastnlo:: ffi;
57+
58+ // TODO: other cases NYI
59+ assert_eq ! ( scales, 1 ) ;
60+
61+ // TODO: convert this into an error?
62+ assert_eq ! ( fun_names. lhapdf_names. len( ) , 1 ) ;
63+
64+ // this creates a file, but doesn't give us an object that we can convolve with a function
65+ let order_mask = fastnlo:: convert_into_fastnlo ( grid, output, discard_non_matching_scales) ?;
66+
67+ // so load this file, giving the right PDF set
68+ let mut file = ffi:: make_fastnlo_lhapdf_with_name_file_set (
69+ output. to_str ( ) . unwrap ( ) ,
70+ & fun_names. lhapdf_names [ 0 ] ,
71+ // UNWRAP: this shouldn't be negative or overflow
72+ fun_names. members [ 0 ] . unwrap_or ( 0 ) . try_into ( ) . unwrap ( ) ,
73+ ) ;
5774
58- let ( mut fastnlo, order_mask) =
59- fastnlo:: convert_into_fastnlo ( grid, output, discard_non_matching_scales) ?;
60- let results = fastnlo:: convolve_fastnlo ( fastnlo. pin_mut ( ) , conv_funs) ;
75+ let mut reader = ffi:: downcast_lhapdf_to_reader_mut ( file. as_mut ( ) . unwrap ( ) ) ;
6176
62- Ok ( ( "fastNLO" , results, 1 , order_mask) )
77+ // fastNLO does not support a fragmentation scale
78+ let unpermuted_results: Vec < _ > = helpers:: SCALES_VECTOR_REN_FAC [ 0 ..scales]
79+ . iter ( )
80+ . map ( |& ( xir, xif, _) | {
81+ if !reader. as_mut ( ) . SetScaleFactorsMuRMuF ( xir, xif) {
82+ return None ;
83+ }
84+ reader. as_mut ( ) . CalcCrossSection ( ) ;
85+ Some ( ffi:: GetCrossSection ( reader. as_mut ( ) , false ) )
86+ } )
87+ . take_while ( Option :: is_some)
88+ . map ( Option :: unwrap)
89+ . collect ( ) ;
90+
91+ assert ! ( matches!( unpermuted_results. len( ) , 1 | 3 | 7 | 9 ) ) ;
92+
93+ let bins = unpermuted_results[ 0 ] . len ( ) ;
94+
95+ let results: Vec < _ > = ( 0 ..bins)
96+ . flat_map ( |bin| unpermuted_results. iter ( ) . map ( move |r| r[ bin] ) )
97+ . collect ( ) ;
98+
99+ Ok ( ( "fastNLO" , results, scales, order_mask) )
63100}
64101
65102#[ cfg( not( feature = "fastnlo" ) ) ]
66103fn convert_into_fastnlo (
67104 _: & Path ,
68105 _: & Grid ,
69- _: & mut [ Pdf ] ,
106+ _: & ConvFuns ,
70107 _: usize ,
71108 _: bool ,
72109) -> Result < ( & ' static str , Vec < f64 > , usize , Vec < bool > ) > {
@@ -79,6 +116,7 @@ fn convert_into_grid(
79116 output : & Path ,
80117 grid : & mut Grid ,
81118 conv_funs : & mut [ Pdf ] ,
119+ fun_names : & ConvFuns ,
82120 scales : usize ,
83121 discard_non_matching_scales : bool ,
84122) -> Result < ( & ' static str , Vec < f64 > , usize , Vec < bool > ) > {
@@ -101,7 +139,7 @@ fn convert_into_grid(
101139 return convert_into_fastnlo (
102140 output,
103141 grid,
104- conv_funs ,
142+ fun_names ,
105143 scales,
106144 discard_non_matching_scales,
107145 ) ;
@@ -158,6 +196,7 @@ impl Subcommand for Opts {
158196 & self . output ,
159197 & mut grid,
160198 & mut conv_funs,
199+ & self . conv_funs ,
161200 self . scales ,
162201 self . discard_non_matching_scales ,
163202 ) ?;
0 commit comments