@@ -299,8 +299,9 @@ static enum ent_return file_get_line_(struct file_buffer ** buffer, int skip)
299
299
if (ptr [size - 1 ] == check ) break ;
300
300
301
301
/* Get more memory then ... */
302
- void * tmp = realloc (* buffer , sizeof (* * buffer ) +
303
- (* buffer )-> size + FILE_BLOCK_SIZE );
302
+ void * tmp = realloc (* buffer ,
303
+ sizeof (* * buffer ) + (* buffer )-> size +
304
+ FILE_BLOCK_SIZE );
304
305
if (tmp == NULL ) return ENT_RETURN_MEMORY_ERROR ;
305
306
* buffer = tmp ;
306
307
ptr = (* buffer )-> line + (* buffer )-> size - 1 ;
@@ -818,10 +819,10 @@ static double dcs_integrate(struct ent_physics * physics,
818
819
for (j = 0 ; j < nx * N_GQ ; j ++ ) {
819
820
const double x = xmin *
820
821
exp ((0.5 + 0.5 * xGQ [j % N_GQ ] + j / N_GQ ) *
821
- dlx );
822
+ dlx );
822
823
J += wGQ [j % N_GQ ] * x *
823
824
dcs_compute (physics , projectile , energy , Z ,
824
- A , process , x , y );
825
+ A , process , x , y );
825
826
}
826
827
I += wGQ [i % N_GQ ] * y * J ;
827
828
}
@@ -842,9 +843,9 @@ static double dcs_integrate(struct ent_physics * physics,
842
843
for (i = 0 ; i < ny * N_GQ ; i ++ ) {
843
844
const double y = ymin *
844
845
exp ((0.5 + 0.5 * xGQ [i % N_GQ ] + i / N_GQ ) * dly );
845
- I += wGQ [i % N_GQ ] * y * dcs_compute ( physics ,
846
- projectile , energy , Z , A ,
847
- process , 0. , y );
846
+ I += wGQ [i % N_GQ ] * y *
847
+ dcs_compute ( physics , projectile , energy , Z , A ,
848
+ process , 0. , y );
848
849
}
849
850
850
851
const double y1min = mu / energy ;
@@ -853,9 +854,9 @@ static double dcs_integrate(struct ent_physics * physics,
853
854
for (i = 0 ; i < ny * N_GQ ; i ++ ) {
854
855
const double y1 = y1min *
855
856
exp ((0.5 + 0.5 * xGQ [i % N_GQ ] + i / N_GQ ) * dly1 );
856
- I1 += wGQ [i % N_GQ ] * y1 * dcs_compute ( physics ,
857
- projectile , energy , Z , A ,
858
- process , 0. , 1. - y1 );
857
+ I1 += wGQ [i % N_GQ ] * y1 *
858
+ dcs_compute ( physics , projectile , energy , Z , A ,
859
+ process , 0. , 1. - y1 );
859
860
}
860
861
861
862
return 0.5 * (I * dly + I1 * dly1 );
@@ -1219,29 +1220,32 @@ enum ent_return ent_physics_cross_section(struct ent_physics * physics,
1219
1220
if ((rc = proget_compute (projectile , ENT_PID_PROTON ,
1220
1221
process , & proget )) != ENT_RETURN_SUCCESS )
1221
1222
ENT_RETURN (rc );
1222
- * cross_section += Z * cross_section_compute (mode ,
1223
- proget , cs0 , cs1 , p1 , p2 );
1223
+ * cross_section += Z *
1224
+ cross_section_compute (
1225
+ mode , proget , cs0 , cs1 , p1 , p2 );
1224
1226
}
1225
1227
const double N = A - Z ;
1226
1228
if (N > 0. ) {
1227
1229
if ((rc = proget_compute (projectile , ENT_PID_NEUTRON ,
1228
1230
process , & proget )) != ENT_RETURN_SUCCESS )
1229
1231
ENT_RETURN (rc );
1230
- * cross_section += N * cross_section_compute (mode ,
1231
- proget , cs0 , cs1 , p1 , p2 );
1232
+ * cross_section += N *
1233
+ cross_section_compute (
1234
+ mode , proget , cs0 , cs1 , p1 , p2 );
1232
1235
}
1233
1236
} else {
1234
1237
int proget ;
1235
1238
if ((rc = proget_compute (projectile , ENT_PID_ELECTRON , process ,
1236
1239
& proget )) != ENT_RETURN_SUCCESS )
1237
1240
ENT_RETURN (rc );
1238
1241
if (proget < PROGET_N - 1 ) {
1239
- * cross_section = Z * cross_section_compute (mode , proget ,
1240
- cs0 , cs1 , p1 , p2 );
1242
+ * cross_section = Z *
1243
+ cross_section_compute (
1244
+ mode , proget , cs0 , cs1 , p1 , p2 );
1241
1245
} else {
1242
1246
* cross_section = Z *
1243
- cross_section_compute (mode , PROGET_N - 2 , cs0 , cs1 ,
1244
- p1 , p2 ) *
1247
+ cross_section_compute (
1248
+ mode , PROGET_N - 2 , cs0 , cs1 , p1 , p2 ) *
1245
1249
(ENT_WIDTH_W / ENT_WIDTH_W_TO_MUON - 1. );
1246
1250
}
1247
1251
}
@@ -1413,11 +1417,12 @@ static enum ent_return transport_step(struct ent_context * context,
1413
1417
if (fabs (drho ) < 1E-03 ) {
1414
1418
ds = 2. * dX / (density1 + * density ) - * step ;
1415
1419
} else {
1416
- ds = * step * ((sqrt (density1 * density1 +
1417
- 2. * dX * drho / * step ) -
1418
- density1 ) /
1419
- drho -
1420
- 1. );
1420
+ ds = * step *
1421
+ ((sqrt (density1 * density1 +
1422
+ 2. * dX * drho / * step ) -
1423
+ density1 ) /
1424
+ drho -
1425
+ 1. );
1421
1426
}
1422
1427
state -> grammage = grammage_max ;
1423
1428
state -> position [0 ] += ds * sgn * state -> direction [0 ];
@@ -1445,6 +1450,8 @@ static enum ent_return transport_step(struct ent_context * context,
1445
1450
if ((step2 > 0. ) && ((step1 <= 0. ) || (step2 < step1 ))) step1 = step2 ;
1446
1451
* step = (step1 < 0 ) ? 0. : step1 ;
1447
1452
* density = density1 ;
1453
+ if (* medium == NULL )
1454
+ * event = ENT_EVENT_EXIT ;
1448
1455
return ENT_RETURN_SUCCESS ;
1449
1456
1450
1457
#undef STEP_MIN
@@ -2015,26 +2022,26 @@ static void transport_rotate(
2015
2022
const double a2 = fabs (direction [2 ]);
2016
2023
if (a0 > a1 ) {
2017
2024
if (a0 > a2 ) {
2018
- const double nrm =
2019
- 1. / sqrt (direction [0 ] * direction [0 ] +
2020
- direction [2 ] * direction [2 ]);
2025
+ const double nrm = 1. /
2026
+ sqrt (direction [0 ] * direction [0 ] +
2027
+ direction [2 ] * direction [2 ]);
2021
2028
u0x = - direction [2 ] * nrm , u0z = direction [0 ] * nrm ;
2022
2029
} else {
2023
- const double nrm =
2024
- 1. / sqrt (direction [1 ] * direction [1 ] +
2025
- direction [2 ] * direction [2 ]);
2030
+ const double nrm = 1. /
2031
+ sqrt (direction [1 ] * direction [1 ] +
2032
+ direction [2 ] * direction [2 ]);
2026
2033
u0y = direction [2 ] * nrm , u0z = - direction [1 ] * nrm ;
2027
2034
}
2028
2035
} else {
2029
2036
if (a1 > a2 ) {
2030
- const double nrm =
2031
- 1. / sqrt (direction [0 ] * direction [0 ] +
2032
- direction [1 ] * direction [1 ]);
2037
+ const double nrm = 1. /
2038
+ sqrt (direction [0 ] * direction [0 ] +
2039
+ direction [1 ] * direction [1 ]);
2033
2040
u0x = direction [1 ] * nrm , u0y = - direction [0 ] * nrm ;
2034
2041
} else {
2035
- const double nrm =
2036
- 1. / sqrt (direction [1 ] * direction [1 ] +
2037
- direction [2 ] * direction [2 ]);
2042
+ const double nrm = 1. /
2043
+ sqrt (direction [1 ] * direction [1 ] +
2044
+ direction [2 ] * direction [2 ]);
2038
2045
u0y = direction [2 ] * nrm , u0z = - direction [1 ] * nrm ;
2039
2046
}
2040
2047
}
@@ -2453,8 +2460,9 @@ static void ancestor_likeliness_fill(struct ent_context * context,
2453
2460
proget_v [* np ] = proget [i ];
2454
2461
const double p0 = (* np > 0 ) ? p [* np - 1 ] : 0. ;
2455
2462
p [* np ] = p0 +
2456
- rho0 * Z * cross_section_compute (
2457
- mode , proget [i ], cs0 , cs1 , p1 , p2 );
2463
+ rho0 * Z *
2464
+ cross_section_compute (
2465
+ mode , proget [i ], cs0 , cs1 , p1 , p2 );
2458
2466
ancestor_v [(* np )++ ] = pid [i ];
2459
2467
}
2460
2468
}
@@ -2584,11 +2592,13 @@ static enum ent_return transport_ancestor_draw(struct ent_physics * physics,
2584
2592
PROGET_NC_NU_NEUTRON :
2585
2593
PROGET_NC_NU_BAR_NEUTRON ;
2586
2594
proget_v [1 ] = proget_v [0 ] + 4 ;
2587
- p [0 ] = rho0 * N * cross_section_compute (mode ,
2588
- proget_v [0 ], cs0 , cs1 , p1 , p2 );
2595
+ p [0 ] = rho0 * N *
2596
+ cross_section_compute (
2597
+ mode , proget_v [0 ], cs0 , cs1 , p1 , p2 );
2589
2598
p [1 ] = p [0 ] +
2590
- rho0 * Z * cross_section_compute (
2591
- mode , proget_v [1 ], cs0 , cs1 , p1 , p2 );
2599
+ rho0 * Z *
2600
+ cross_section_compute (
2601
+ mode , proget_v [1 ], cs0 , cs1 , p1 , p2 );
2592
2602
2593
2603
/* Elastic event on an atomic electron. */
2594
2604
if (apid == ENT_PID_NU_E )
@@ -2599,8 +2609,9 @@ static enum ent_return transport_ancestor_draw(struct ent_physics * physics,
2599
2609
proget_v [2 ] = PROGET_ELASTIC_NU_TAU ;
2600
2610
if (daughter -> pid < 0 ) proget_v [2 ]++ ;
2601
2611
p [2 ] = p [1 ] +
2602
- rho0 * Z * cross_section_compute (
2603
- mode , proget_v [2 ], cs0 , cs1 , p1 , p2 );
2612
+ rho0 * Z *
2613
+ cross_section_compute (
2614
+ mode , proget_v [2 ], cs0 , cs1 , p1 , p2 );
2604
2615
2605
2616
ancestor_v [np ++ ] = daughter -> pid ;
2606
2617
ancestor_v [np ++ ] = daughter -> pid ;
@@ -2651,9 +2662,9 @@ static enum ent_return transport_ancestor_draw(struct ent_physics * physics,
2651
2662
proget_v [np ] = PROGET_INVERSE_NU_MU_MU ;
2652
2663
const double p0 = (np > 0 ) ? p [np - 1 ] : 0. ;
2653
2664
p [np ] = p0 +
2654
- rho0 * Z * cross_section_compute ( mode ,
2655
- proget_v [ np ], cs0 , cs1 , p1 ,
2656
- p2 );
2665
+ rho0 * Z *
2666
+ cross_section_compute ( mode ,
2667
+ proget_v [ np ], cs0 , cs1 , p1 , p2 );
2657
2668
ancestor_v [np ++ ] = ENT_PID_NU_MU ;
2658
2669
}
2659
2670
const double rho1 = context -> ancestor (
@@ -2662,9 +2673,9 @@ static enum ent_return transport_ancestor_draw(struct ent_physics * physics,
2662
2673
proget_v [np ] = PROGET_INVERSE_NU_TAU_TAU ;
2663
2674
const double p0 = (np > 0 ) ? p [np - 1 ] : 0. ;
2664
2675
p [np ] = p0 +
2665
- rho1 * Z * cross_section_compute ( mode ,
2666
- proget_v [ np ], cs0 , cs1 , p1 ,
2667
- p2 );
2676
+ rho1 * Z *
2677
+ cross_section_compute ( mode ,
2678
+ proget_v [ np ], cs0 , cs1 , p1 , p2 );
2668
2679
ancestor_v [np ++ ] = ENT_PID_NU_TAU ;
2669
2680
}
2670
2681
} else if ((daughter -> pid == ENT_PID_NU_BAR_MU ) ||
@@ -2678,9 +2689,9 @@ static enum ent_return transport_ancestor_draw(struct ent_physics * physics,
2678
2689
PROGET_INVERSE_NU_BAR_E_TAU ;
2679
2690
const double p0 = (np > 0 ) ? p [np - 1 ] : 0. ;
2680
2691
p [np ] = p0 +
2681
- rho0 * Z * cross_section_compute ( mode ,
2682
- proget_v [ np ], cs0 , cs1 , p1 ,
2683
- p2 );
2692
+ rho0 * Z *
2693
+ cross_section_compute ( mode ,
2694
+ proget_v [ np ], cs0 , cs1 , p1 , p2 );
2684
2695
ancestor_v [np ++ ] = ENT_PID_NU_BAR_E ;
2685
2696
}
2686
2697
}
@@ -2694,11 +2705,13 @@ static enum ent_return transport_ancestor_draw(struct ent_physics * physics,
2694
2705
PROGET_CC_NU_NEUTRON :
2695
2706
PROGET_CC_NU_BAR_NEUTRON ;
2696
2707
proget_v [1 ] = proget_v [0 ] + 4 ;
2697
- p [0 ] = rho0 * N * cross_section_compute (mode ,
2698
- proget_v [0 ], cs0 , cs1 , p1 , p2 );
2708
+ p [0 ] = rho0 * N *
2709
+ cross_section_compute (
2710
+ mode , proget_v [0 ], cs0 , cs1 , p1 , p2 );
2699
2711
p [1 ] = p [0 ] +
2700
- rho0 * Z * cross_section_compute (
2701
- mode , proget_v [1 ], cs0 , cs1 , p1 , p2 );
2712
+ rho0 * Z *
2713
+ cross_section_compute (
2714
+ mode , proget_v [1 ], cs0 , cs1 , p1 , p2 );
2702
2715
2703
2716
ancestor_v [np ++ ] = npid ;
2704
2717
ancestor_v [np ++ ] = npid ;
@@ -2752,10 +2765,9 @@ static enum ent_return vertex_dis_compute(struct ent_physics * physics,
2752
2765
/* Compute the relevant cross-sections and randomise the
2753
2766
* target accordingly.
2754
2767
*/
2755
- * cs_p = (medium -> Z > 0. ) ?
2756
- medium -> Z *
2768
+ * cs_p = (medium -> Z > 0. ) ? medium -> Z *
2757
2769
cross_section_compute (mode , proget_p , cs0 , cs1 , p1 , p2 ) :
2758
- 0. ;
2770
+ 0. ;
2759
2771
const double N = medium -> A - medium -> Z ;
2760
2772
* cs_n = (N > 0. ) ?
2761
2773
N * cross_section_compute (mode , proget_n , cs0 , cs1 , p1 , p2 ) :
@@ -3096,6 +3108,7 @@ enum ent_return ent_transport(struct ent_physics * physics,
3096
3108
if (step )
3097
3109
for (;;) {
3098
3110
/* Step until an event occurs. */
3111
+ struct ent_medium * m = medium ;
3099
3112
if ((rc = transport_step (context , state , & medium , & step ,
3100
3113
& density , Xlim , & event_ )) !=
3101
3114
ENT_RETURN_SUCCESS )
@@ -3105,6 +3118,16 @@ enum ent_return ent_transport(struct ent_physics * physics,
3105
3118
rc = ENT_RETURN_DOMAIN_ERROR ;
3106
3119
goto exit ;
3107
3120
}
3121
+
3122
+ /* Call any custom stepping action if a medium
3123
+ * change occured.
3124
+ */
3125
+ if ((context -> stepping_action != NULL ) &&
3126
+ (medium != m )) {
3127
+ if ((rc = context -> stepping_action (context ,
3128
+ medium , state )) != ENT_RETURN_SUCCESS )
3129
+ goto exit ;
3130
+ }
3108
3131
}
3109
3132
else {
3110
3133
/* This is a uniform medium of infinite extension.
@@ -3113,6 +3136,13 @@ enum ent_return ent_transport(struct ent_physics * physics,
3113
3136
event_ = transport_straight (context , state , density , Xlim );
3114
3137
}
3115
3138
3139
+ /* Call any custom stepping action. */
3140
+ if (context -> stepping_action != NULL ) {
3141
+ if ((rc = context -> stepping_action (context , medium , state )) !=
3142
+ ENT_RETURN_SUCCESS )
3143
+ goto exit ;
3144
+ }
3145
+
3116
3146
/* Process any interaction. */
3117
3147
if ((event_ == ENT_EVENT_LIMIT_GRAMMAGE ) &&
3118
3148
(foreseen == ENT_EVENT_NONE )) {
0 commit comments