@@ -111,8 +111,19 @@ pub fn convert_into_applgrid(
111111 bail ! ( "grid has non-consecutive bin limits, which APPLgrid does not support" ) ;
112112 }
113113
114- if grid. convolutions ( ) . len ( ) > 2 {
115- bail ! ( "APPLgrid does not support grids with more than two convolutions" ) ;
114+ match grid. convolutions ( ) {
115+ [ _] => { }
116+ [ a, b] => {
117+ if a != b {
118+ if a. cc ( ) == * b {
119+ // use charge conjugate to map hadron-anti-hadron grids to use the same single
120+ // convolution function
121+ let index = if a. pid ( ) < 0 { 0 } else { 1 } ;
122+ grid. charge_conjugate ( index) ;
123+ }
124+ }
125+ }
126+ _ => bail ! ( "APPLgrid does not support grids with more than two convolutions" ) ,
116127 }
117128
118129 // APPLgrid only understands PDG PIDs
@@ -156,9 +167,11 @@ pub fn convert_into_applgrid(
156167 . collect ( ) ;
157168
158169 // `id` must end with '.config' for APPLgrid to know its type is `lumi_pdf`
159- let id = "PineAPPL-Lumi.config" ;
170+ let id = format ! ( "{}.config" , output. file_stem( )
171+ // UNWRAP: because we write to that file in the end, there always must be a file name
172+ . unwrap( ) . to_string_lossy( ) ) ;
160173 // this object is managed by APPLgrid internally
161- ffi:: make_lumi_pdf ( id, & combinations) . into_raw ( ) ;
174+ ffi:: make_lumi_pdf ( & id, & combinations) . into_raw ( ) ;
162175
163176 let limits: Vec < _ > = grid
164177 . bwfl ( )
@@ -200,17 +213,17 @@ pub fn convert_into_applgrid(
200213 - lo_alphas;
201214
202215 let mut applgrid =
203- ffi:: make_empty_grid ( & limits, id, lo_alphas. into ( ) , loops. into ( ) , "f2" , "h0" ) ;
216+ ffi:: make_empty_grid ( & limits, & id, lo_alphas. into ( ) , loops. into ( ) , "f2" , "h0" ) ;
204217
205- let has_pdf1 = !grid . convolutions ( ) . is_empty ( ) ;
206- let has_pdf2 = grid. convolutions ( ) . get ( 1 ) . is_some ( ) ;
218+ // APPLgrid has either two or one convolution(s)
219+ let convolutions = grid. convolutions ( ) . len ( ) ;
207220
208- for ( appl_order , order) in order_mask
221+ for order in order_mask
209222 . iter ( )
210223 . enumerate ( )
211224 . filter_map ( |( index, keep) | keep. then_some ( index) )
212- . enumerate ( )
213225 {
226+ let appl_order = grid. orders ( ) [ order] . alphas - lo_alphas;
214227 let factor = TAU . powi ( grid. orders ( ) [ order] . alphas . into ( ) ) ;
215228
216229 for ( bin, subgrids) in grid
@@ -275,9 +288,7 @@ pub fn convert_into_applgrid(
275288 } )
276289 . collect :: < Result < _ > > ( ) ?;
277290
278- // in the DIS case APPLgrid always uses the first x dimension
279-
280- let ( x1_grid, x2_grid) = if has_pdf1 && has_pdf2 {
291+ let ( x1_grid, x2_grid) = if convolutions == 2 {
281292 (
282293 grid. kinematics ( )
283294 . iter ( )
@@ -298,26 +309,13 @@ pub fn convert_into_applgrid(
298309 // TODO: convert this into an error
299310 . unwrap ( ) ,
300311 )
301- } else if has_pdf1 {
302- (
303- grid. kinematics ( )
304- . iter ( )
305- . zip ( subgrid. node_values ( ) )
306- . find_map ( |( kin, node_values) | {
307- matches ! ( kin, & Kinematics :: X ( idx) if idx == 0 )
308- . then_some ( node_values)
309- } )
310- // TODO: convert this into an error
311- . unwrap ( ) ,
312- Vec :: new ( ) ,
313- )
314312 } else {
315313 (
316314 grid. kinematics ( )
317315 . iter ( )
318316 . zip ( subgrid. node_values ( ) )
319317 . find_map ( |( kin, node_values) | {
320- matches ! ( kin, & Kinematics :: X ( idx) if idx == 1 )
318+ matches ! ( kin, & Kinematics :: X ( idx) if idx == 0 )
321319 . then_some ( node_values)
322320 } )
323321 // TODO: convert this into an error
@@ -376,7 +374,7 @@ pub fn convert_into_applgrid(
376374 weightgrid. as_mut ( ) ,
377375 appl_q2_idx,
378376 appl_x1_idx[ indices[ 1 ] ] ,
379- if has_pdf1 && has_pdf2 {
377+ if convolutions == 2 {
380378 appl_x2_idx[ indices[ 2 ] ]
381379 } else {
382380 0
0 commit comments