|
16 | 16 | #include "EMNonLin.h" |
17 | 17 |
|
18 | 18 | #include <algorithm> |
| 19 | +#include <cmath> |
19 | 20 |
|
20 | 21 | using namespace o2::pwgem::nonlin; |
21 | 22 |
|
22 | | -float EMNonLin::getCorrectionFactor(float x, const Context& ctx) |
| 23 | +float EMNonLin::getCorrectionFactor(float var, const Context& ctx) |
23 | 24 | { |
24 | | - if (!ctx.params || x == 0.f) [[unlikely]] { |
25 | | - return x; |
| 25 | + if (!ctx.params || var == 0.f) [[unlikely]] { |
| 26 | + return 1.f; |
26 | 27 | } |
27 | 28 |
|
28 | 29 | int maxIter = std::min(ctx.nIter, MaxIter - 1); |
29 | | - |
30 | | - float scale = 1.f; // cumulative scale |
31 | | - float refVal = x; // reference value for computing next scale |
| 30 | + float scale = 1.f; // cumulative scale |
| 31 | + float refVal = var; // reference value updated each iteration |
32 | 32 |
|
33 | 33 | for (int i = 0; i <= maxIter; ++i) { |
34 | 34 | if (refVal == 0.f) { |
35 | 35 | break; |
36 | 36 | } |
37 | | - |
38 | 37 | const auto& p = ctx.params[i]; |
39 | 38 |
|
40 | | - // scale function (x + a + b/x)/(x + c) which goes towards 1 for large x since x >> a,b,c -> x/x = 1 |
41 | | - float iterScale = |
42 | | - (refVal + p.par0 + p.par1 / refVal) / |
43 | | - (refVal + p.par2); |
| 39 | + // evaluate pol1 for each parameter at this centrality |
| 40 | + float a = p.a0 + p.a1 * ctx.cent; |
| 41 | + float b = p.b0 + p.b1 * ctx.cent; |
| 42 | + float c = p.c0 + p.c1 * ctx.cent; |
44 | 43 |
|
45 | | - scale *= iterScale; // total scale = product over itertaion scale |
46 | | - refVal = x * scale; // next iteration uses scaled original input |
47 | | - } |
48 | | - return scale; |
49 | | -} |
50 | | - |
51 | | -const EMNonLin::NonLinParams* EMNonLin::resolveParams(PhotonType type, float cent) |
52 | | -{ |
53 | | - int centBin = static_cast<int>(cent / 10.f); |
54 | | - if (centBin < 0) |
55 | | - centBin = 0; |
56 | | - if (centBin >= CentBins) |
57 | | - centBin = CentBins - 1; |
58 | | - |
59 | | - return &kNonLinTable[static_cast<int>(type)][centBin][0]; |
60 | | -} |
| 44 | + // guard against c <= 0 which would make pow(x, -c) diverge |
| 45 | + if (c <= 0.f) { |
| 46 | + continue; |
| 47 | + } |
61 | 48 |
|
62 | | -const EMNonLin::NonLinParams* EMNonLin::resolveParamsMC(PhotonType type, float cent) |
63 | | -{ |
64 | | - int centBin = static_cast<int>(cent / 10.f); |
65 | | - if (centBin < 0) |
66 | | - centBin = 0; |
67 | | - if (centBin >= CentBins) |
68 | | - centBin = CentBins - 1; |
| 49 | + float iterScale = a + b * std::pow(refVal, -c); |
| 50 | + scale *= iterScale; |
| 51 | + refVal = var * scale; // next iteration uses scaled original input |
| 52 | + } |
69 | 53 |
|
70 | | - return &kNonLinTableMC[static_cast<int>(type)][centBin][0]; |
| 54 | + return scale; |
71 | 55 | } |
0 commit comments