FittingFunctions.icc
Go to the documentation of this file.
1 /* FITTING FUNCTIONS */
2 
3 /* Different power-law-like fit functions to describe the measured flux */
4 
5 
8  };
9 
10 
11 double SpectrumLgSmoothFitFunction2013(double* x, double* par)
12 {
13 
14  /* ICRC 2013 model:
15 
16  0: J0 (normalization);
17  1: log10(Eankle) (energy in log10 at ankle position);
18  2: gamma1 (spectral index before ankle);
19  3: gamma2 (spectral index after ankle);
20  4: log10(Es) (energy in log10 at the 1/2 suppression);
21  5: log10(Wc) (suppression smoothness )
22  */
23 
24  const double lgE = x[0];
25 
26  double lgJ;
27 
28  if (lgE < par[1])
29  lgJ = par[0] - par[2] * (lgE - par[1]);
30  else {
31  double lgJ_exp = -par[3] * lgE - log10(1.0 + exp((lgE - par[4]) / par[5]));
32  double lgJ_ankle = -par[3] * par[1] - log10(1.0 + exp((par[1] - par[4]) / par[5]));
33  lgJ = par[0] + lgJ_exp - lgJ_ankle;
34  }
35 
36  return pow(10, lgJ);
37 }
38 
39 
40 double SpectrumLgSmoothFitFunction2015(double* x, double* par)
41 {
42 
43  /* ICRC 2015/2017 model:
44 
45  0: J0 (normalization);
46  1: log10(Eankle) (energy in log10 at ankle position);
47  2: gamma1 (spectral index before ankle);
48  3: gamma2 (spectral index after ankle);
49  4: log10(Es) (energy in log10 at the 1/2 suppression);
50  5: Delta gamma (increment of the spectral index beyond suppression)
51  */
52 
53 
54  const double lgE = x[0];
55 
56  double lgJ;
57 
58  if (lgE < par[1])
59  lgJ = par[0] - par[2] * (lgE - par[1]);
60  else {
61  double E = pow(10., lgE);
62  double Ea = pow(10, par[1]);
63  double Es = pow(10, par[4]);
64 
65  double lgJ_exp = log10(1.0 + pow(E / Es, par[5]));
66  double lgJ_ankle = log10(1.0 + pow(Ea / Es, par[5]));
67  lgJ = par[0] - par[3] * (lgE - par[1]) + lgJ_ankle - lgJ_exp ;
68  }
69 
70  return pow(10, lgJ);
71 }
72 
73 
74 double
75 FluxModelMultiSmoothBreak(double* x, double* par)
76 {
77  /* ICRC 2017? model for unfolding (not for spectrum fit):
78  Smooth model with additional break as proposed by Oliver
79  Should be used only for the unfolding to avoid non-diff features in correction factor
80 
81  0: J0 (normalization);
82  1: log10(Eankle) (energy in log10 at ankle position);
83  2: log10(Ex) (energy in log10 at additional break);
84  3: log10(Es) (energy in log10 at the 1/2 suppression);
85  4: gamma1 (spectral index before ankle);
86  5: gamma2 (spectral index after ankle but before x-break);
87  6: gamma3 (spectral index after x-break but before suppression);
88  7: gamma4 (spectral index after suppression);
89 
90  */
91 
92  const size_t n = 8;
93  const size_t breaks = n / 2 - 1;
94  const double lgE = x[0];
95 
96  double lgJ = par[0] - par[breaks + 1] * (lgE - 18.5);
97 
98  for (size_t i = 1; i <= breaks; ++i) {
99  lgJ += TMath::Log10(1 + pow(10, par[breaks + i] * (lgE - par[i])));
100  lgJ -= TMath::Log10(1 + pow(10, par[breaks + i + 1] * (lgE - par[i])));
101  }
102 
103  return pow(10, lgJ);
104 }
105 
106 
107 double SpectrumInfillFitFunction(double* x, double* par)
108 {
109  // Model: only upto ankle --> J0, Eank, gamma1, gamma2
110 
111  const double lgE = x[0];
112 
113  double lgJ;
114 
115  if (lgE < par[1])
116  lgJ = par[0] - par[2] * (lgE - par[1]);
117  else
118  lgJ = par[0] - par[3] * (lgE - par[1]);
119 
120  return pow(10, lgJ);
121 }
122 
123 
124 // TVectorD versions of the above functions
125 
126 TVectorD SpectrumLgSmoothFitFunction2013(TVectorD x, double* par)
127 {
128  int ncol = x.GetNoElements();
129  TVectorD J(ncol);
130 
131  for (int i = 0; i < ncol; ++i)
132  J[i] = SpectrumLgSmoothFitFunction2013(&x[i], par);
133 
134  return J;
135 }
136 
137 
138 TVectorD SpectrumLgSmoothFitFunction2015(TVectorD x, double* par)
139 {
140  int ncol = x.GetNoElements();
141  TVectorD J(ncol);
142 
143  for (int i = 0; i < ncol; ++i)
144  J[i] = SpectrumLgSmoothFitFunction2015(&x[i], par);
145 
146  return J;
147 }
148 
149 
150 TVectorD FluxModelMultiSmoothBreak(TVectorD x, double* par)
151 {
152  int ncol = x.GetNoElements();
153  TVectorD J(ncol);
154 
155  for (int i = 0; i < ncol; ++i)
156  J[i] = FluxModelMultiSmoothBreak(&x[i], par);
157 
158  return J;
159 }
160 
161 
162 TVectorD SpectrumInfillFitFunction(TVectorD x, double* par)
163 {
164  int ncol = x.GetNoElements();
165  TVectorD J(ncol);
166 
167  for (int i = 0; i < ncol; ++i)
168  J[i] = SpectrumInfillFitFunction(&x[i], par);
169 
170  return J;
171 }
172 
173 
174 // selects one of the implemented models according to the modeltype
175 double FluxModel(const modeltype mtype, double* x, double* par)
176 {
177  switch (mtype) {
178  case StandardICRC2013:
179  return SpectrumLgSmoothFitFunction2013(x, par);
180  case StandardICRC2015:
181  return SpectrumLgSmoothFitFunction2015(x, par);
182  case StandardMultiSmooth:
183  return FluxModelMultiSmoothBreak(x, par);
184  case InfillHard:
185  return SpectrumInfillFitFunction(x, par);
186  }
187 
188  return SpectrumLgSmoothFitFunction2013(x, par);
189 }
190 
191 
192 // change also this function to changes of the above function
193 // unfortunately, cannot be easily changed to template
194 TVectorD FluxModel(const modeltype mtype, TVectorD x, double* par)
195 {
196  switch (mtype) {
197  case StandardICRC2013:
198  return SpectrumLgSmoothFitFunction2013(x, par);
199  case StandardICRC2015:
200  return SpectrumLgSmoothFitFunction2015(x, par);
201  case StandardMultiSmooth:
202  return FluxModelMultiSmoothBreak(x, par);
203  case InfillHard:
204  return SpectrumInfillFitFunction(x, par);
205  }
206 
207  return SpectrumLgSmoothFitFunction2013(x, par);
208 }
209 
210 double
211 (*FluxModels(const modeltype mtype))(double*, double*)
212 {
213  switch (mtype) {
214  case StandardICRC2013:
216  case StandardICRC2015:
218  case StandardMultiSmooth:
220  case InfillHard:
222  }
223 
225 }
226 
227 
228 TVectorD GetCorrectionFactor(const TVectorD x, const TMatrixD m, double* par, const modeltype mtype)
229 {
230 
231  int ncol = x.GetNoElements();
232  TVectorD f0s = FluxModel(mtype, x, par);
233 
234  for (int i = 0; i < ncol; ++i)
235  f0s[i] = f0s[i] * pow(10, x[i]);
236 
237  TVectorD f1s = m * f0s;
238  f1s *= (x[1] - x[0]);
239 
240  TVectorD corr(ncol);
241  for (int i = 0; i < ncol; ++i)
242  corr[i] = f0s[i] / f1s[i];
243 
244  return corr;
245 
246 }
247 
248 
249 TVectorD GetCorrectionFactor(TVectorD parsFit, const modeltype mtype)
250 {
251 
252  int ncol = vecLgE.GetNoElements();
253 
254  double* par = &parsFit[0];
255  TVectorD f0s = FluxModel(mtype, vecLgE, par);
256 
257  for (int i = 0; i < ncol; ++i)
258  f0s[i] = f0s[i] * pow(10, vecLgE[i]);
259 
260  TVectorD f1s = kmatrix * f0s;
261  f1s *= (vecLgE[1] - vecLgE[0]);
262 
263  TVectorD corr(ncol);
264  for (int i = 0; i < ncol; ++i)
265  corr[i] = f0s[i] / f1s[i];
266 
267  return corr;
268 
269 }
double FluxModel(const modeltype mtype, double *x, double *par)
modeltype
double SpectrumInfillFitFunction(double *x, double *par)
double pow(const double x, const unsigned int i)
double FluxModelMultiSmoothBreak(double *x, double *par)
TVectorD parsFit
double(*)(double *, double *) FluxModels(const modeltype mtype)
double SpectrumLgSmoothFitFunction2013(double *x, double *par)
TMatrixD kmatrix
TVectorD vecLgE
constexpr double m
Definition: AugerUnits.h:121
TVectorD GetCorrectionFactor(const TVectorD x, const TMatrixD m, double *par, const modeltype mtype)
double SpectrumLgSmoothFitFunction2015(double *x, double *par)

, generated on Tue Sep 26 2023.