GCC Code Coverage Report


Directory: ./
File: src/iguana/algorithms/clas12/rga/MomentumCorrection/Algorithm.cc
Date: 2025-11-25 17:57:04
Coverage Exec Excl Total
Lines: 65.2% 118 0 181
Functions: 77.8% 7 0 9
Branches: 53.1% 104 0 196

Line Branch Exec Source
1 #include "Algorithm.h"
2 #include <cmath>
3
4 namespace iguana::clas12::rga {
5
6 REGISTER_IGUANA_ALGORITHM(MomentumCorrection);
7
8 5 void MomentumCorrection::Start(hipo::banklist& banks)
9 {
10
2/4
✓ Branch 3 → 4 taken 5 times.
✗ Branch 3 → 24 not taken.
✓ Branch 4 → 5 taken 5 times.
✗ Branch 4 → 7 not taken.
5 b_particle = GetBankIndex(banks, "REC::Particle");
11
2/4
✓ Branch 10 → 11 taken 5 times.
✗ Branch 10 → 30 not taken.
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 14 taken 5 times.
5 b_sector = GetBankIndex(banks, "REC::Particle::Sector");
12
2/4
✓ Branch 17 → 18 taken 5 times.
✗ Branch 17 → 36 not taken.
✓ Branch 18 → 19 taken 5 times.
✗ Branch 18 → 21 not taken.
5 b_config = GetBankIndex(banks, "RUN::config");
13 5 }
14
15
16 1961 bool MomentumCorrection::Run(hipo::banklist& banks) const
17 {
18
1/2
✓ Branch 8 → 9 taken 1961 times.
✗ Branch 8 → 25 not taken.
1961 return Run(
19
3/8
✓ Branch 6 → 7 taken 1961 times.
✗ Branch 6 → 31 not taken.
✓ Branch 7 → 8 taken 1961 times.
✗ Branch 7 → 25 not taken.
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 17 taken 1961 times.
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 34 not taken.
3922 GetBank(banks, b_particle, "REC::Particle"),
20
3/8
✓ Branch 4 → 5 taken 1961 times.
✗ Branch 4 → 37 not taken.
✓ Branch 5 → 6 taken 1961 times.
✗ Branch 5 → 31 not taken.
✓ Branch 19 → 20 taken 1961 times.
✗ Branch 19 → 22 not taken.
✗ Branch 37 → 38 not taken.
✗ Branch 37 → 40 not taken.
3922 GetBank(banks, b_sector, "REC::Particle::Sector"),
21
1/2
✓ Branch 3 → 4 taken 1961 times.
✗ Branch 3 → 37 not taken.
3922 GetBank(banks, b_config, "RUN::config"));
22 }
23
24
25 2044 bool MomentumCorrection::Run(
26 hipo::bank& particleBank,
27 hipo::bank const& sectorBank,
28 hipo::bank const& configBank) const
29 {
30
1/2
✓ Branch 5 → 6 taken 2044 times.
✗ Branch 5 → 35 not taken.
4088 ShowBank(particleBank, Logger::Header("INPUT PARTICLES"));
31
32 2044 auto torus = configBank.getFloat("torus", 0);
33
34
2/2
✓ Branch 24 → 14 taken 9721 times.
✓ Branch 24 → 25 taken 2044 times.
11765 for(auto const& row : particleBank.getRowList()) {
35
36
1/2
✓ Branch 19 → 20 taken 9721 times.
✗ Branch 19 → 41 not taken.
19442 auto [px, py, pz] = Transform(
37 9721 particleBank.getFloat("px", row),
38 9721 particleBank.getFloat("py", row),
39 9721 particleBank.getFloat("pz", row),
40 sectorBank.getInt("sector", row),
41 particleBank.getInt("pid", row),
42 torus);
43
1/2
✓ Branch 20 → 21 taken 9721 times.
✗ Branch 20 → 41 not taken.
9721 particleBank.putFloat("px", row, px);
44
1/2
✓ Branch 21 → 22 taken 9721 times.
✗ Branch 21 → 41 not taken.
9721 particleBank.putFloat("py", row, py);
45
1/2
✓ Branch 22 → 23 taken 9721 times.
✗ Branch 22 → 41 not taken.
9721 particleBank.putFloat("pz", row, pz);
46 }
47
48
1/2
✓ Branch 28 → 29 taken 2044 times.
✗ Branch 28 → 42 not taken.
4088 ShowBank(particleBank, Logger::Header("OUTPUT PARTICLES"));
49 2044 return true;
50 }
51
52
53 9922 Momentum3 MomentumCorrection::Transform(vector_element_t const px, vector_element_t const py, vector_element_t const pz, int const sec, int const pid, float const torus) const
54 {
55 // energy loss correction
56 auto e_cor = torus < 0
57
1/2
✓ Branch 2 → 3 taken 9922 times.
✗ Branch 2 → 4 not taken.
9922 ? EnergyLossInbending(px, py, pz, pid)
58 : EnergyLossOutbending(px, py, pz, pid);
59 // momentum correction
60 auto p_cor = torus < 0
61
1/2
✓ Branch 5 → 6 taken 9922 times.
✗ Branch 5 → 7 not taken.
9922 ? CorrectionInbending(e_cor * px, e_cor * py, e_cor * pz, sec, pid)
62 : CorrectionOutbending(e_cor * px, e_cor * py, e_cor * pz, sec, pid);
63 // return the corrected momentum
64 return {
65 9922 e_cor * p_cor * px,
66 9922 e_cor * p_cor * py,
67 9922 e_cor * p_cor * pz};
68 }
69
70
71 9922 double MomentumCorrection::CorrectionInbending(vector_element_t const px, vector_element_t const py, vector_element_t const pz, int const sec, int const pid) const
72 {
73
74 // skip the correction if it's not defined
75
4/4
✓ Branch 2 → 3 taken 6166 times.
✓ Branch 2 → 4 taken 3756 times.
✓ Branch 3 → 4 taken 1499 times.
✓ Branch 3 → 69 taken 4667 times.
9922 if(!(pid == particle::electron || pid == particle::pi_plus || pid == particle::pi_minus || pid == particle::proton))
76 return 1.0;
77
78 // skip if the sector is unknown
79
2/2
✓ Branch 4 → 5 taken 3433 times.
✓ Branch 4 → 69 taken 1822 times.
5255 if(!IsValidSector(sec))
80 return 1.0;
81
82 // Momentum Magnitude
83 3433 double pp = sqrt(px * px + py * py + pz * pz);
84
85 // Initializing the correction factor
86 double dp = 0;
87
88 // Defining Phi Angle
89 3433 double Phi = (180 / M_PI) * atan2(py, px);
90
91 // (Initial) Shift of the Phi Angle (done to realign sectors whose data is separated when plotted from ±180˚)
92
8/8
✓ Branch 5 → 6 taken 1073 times.
✓ Branch 5 → 7 taken 2360 times.
✓ Branch 6 → 7 taken 917 times.
✓ Branch 6 → 9 taken 156 times.
✓ Branch 7 → 8 taken 1128 times.
✓ Branch 7 → 10 taken 2149 times.
✓ Branch 8 → 9 taken 1108 times.
✓ Branch 8 → 10 taken 20 times.
3433 if(((sec == 4 || sec == 3) && Phi < 0) || (sec > 4 && Phi < 90)) {
93 1264 Phi += 360;
94 }
95
96 // Getting Local Phi Angle
97 3433 double PhiLocal = Phi - (sec - 1) * 60;
98
99 // Applying Shift Functions to Phi Angles (local shifted phi = phi)
100 double phi = PhiLocal;
101
102 // For Electron Shift
103
2/2
✓ Branch 10 → 11 taken 332 times.
✓ Branch 10 → 12 taken 3101 times.
3433 if(pid == particle::electron) {
104 332 phi = PhiLocal - 30 / pp;
105 }
106
107 // For π+ Pion/Proton Shift
108
2/2
✓ Branch 12 → 13 taken 2278 times.
✓ Branch 12 → 14 taken 1155 times.
3433 if(pid == particle::pi_plus || pid == particle::proton) {
109 2278 phi = PhiLocal + (32 / (pp - 0.05));
110 }
111
112 // For π- Pion Shift
113
2/2
✓ Branch 14 → 15 taken 823 times.
✓ Branch 14 → 16 taken 2610 times.
3433 if(pid == particle::pi_minus) {
114 823 phi = PhiLocal - (32 / (pp - 0.05));
115 }
116
117 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
118 //==================================================================================================================================//
119 //=======================//=======================// Electron Corrections //=======================//=======================//
120 //==================================================================================================================================//
121 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
122
2/2
✓ Branch 16 → 17 taken 332 times.
✓ Branch 16 → 29 taken 3101 times.
3433 if(pid == particle::electron) {
123
2/2
✓ Branch 17 → 18 taken 52 times.
✓ Branch 17 → 19 taken 280 times.
332 if(sec == 1) {
124 // The CONTINUOUS QUADRATIC function predicted for ∆p_{El} for [Cor = Uncorrected][Sector 1] is:
125 52 dp = ((-4.3303e-06) * phi * phi + (1.1006e-04) * phi + (-5.7235e-04)) * pp * pp + ((3.2555e-05) * phi * phi + (-0.0014559) * phi + (0.0014878)) * pp + ((-1.9577e-05) * phi * phi + (0.0017996) * phi + (0.025963));
126 }
127
2/2
✓ Branch 19 → 20 taken 70 times.
✓ Branch 19 → 21 taken 262 times.
332 if(sec == 2) {
128 // The CONTINUOUS QUADRATIC function predicted for ∆p_{El} for [Cor = Uncorrected][Sector 2] is:
129 70 dp = ((-9.8045e-07) * phi * phi + (6.7395e-05) * phi + (-4.6757e-05)) * pp * pp + ((-1.4958e-05) * phi * phi + (-0.0011191) * phi + (-0.0025143)) * pp + ((1.2699e-04) * phi * phi + (0.0033121) * phi + (0.020819));
130 }
131
2/2
✓ Branch 21 → 22 taken 56 times.
✓ Branch 21 → 23 taken 276 times.
332 if(sec == 3) {
132 // The CONTINUOUS QUADRATIC function predicted for ∆p_{El} for [Cor = Uncorrected][Sector 3] is:
133 56 dp = ((-5.9459e-07) * phi * phi + (-2.8289e-05) * phi + (-4.3541e-04)) * pp * pp + ((-1.5025e-05) * phi * phi + (5.7730e-04) * phi + (-0.0077582)) * pp + ((7.3348e-05) * phi * phi + (-0.001102) * phi + (0.057052));
134 }
135
2/2
✓ Branch 23 → 24 taken 29 times.
✓ Branch 23 → 25 taken 303 times.
332 if(sec == 4) {
136 // The CONTINUOUS QUADRATIC function predicted for ∆p_{El} for [Cor = Uncorrected][Sector 4] is:
137 29 dp = ((-2.2714e-06) * phi * phi + (-3.0360e-05) * phi + (-8.9322e-04)) * pp * pp + ((2.9737e-05) * phi * phi + (5.1142e-04) * phi + (0.0045641)) * pp + ((-1.0582e-04) * phi * phi + (-5.6852e-04) * phi + (0.027506));
138 }
139
2/2
✓ Branch 25 → 26 taken 68 times.
✓ Branch 25 → 27 taken 264 times.
332 if(sec == 5) {
140 // The CONTINUOUS QUADRATIC function predicted for ∆p_{El} for [Cor = Uncorrected][Sector 5] is:
141 68 dp = ((-1.1490e-06) * phi * phi + (-6.2147e-06) * phi + (-4.7235e-04)) * pp * pp + ((3.7039e-06) * phi * phi + (-1.5943e-04) * phi + (-8.5238e-04)) * pp + ((4.4069e-05) * phi * phi + (0.0014152) * phi + (0.031933));
142 }
143
2/2
✓ Branch 27 → 28 taken 57 times.
✓ Branch 27 → 29 taken 275 times.
332 if(sec == 6) {
144 // The CONTINUOUS QUADRATIC function predicted for ∆p_{El} for [Cor = Uncorrected][Sector 6] is:
145 57 dp = ((1.1076e-06) * phi * phi + (4.0156e-05) * phi + (-1.6341e-04)) * pp * pp + ((-2.8613e-05) * phi * phi + (-5.1861e-04) * phi + (-0.0056437)) * pp + ((1.2419e-04) * phi * phi + (4.9084e-04) * phi + (0.049976));
146 }
147 }
148
149 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
150 //====================================================================================================================================//
151 //=========================//=========================// π+ Corrections //=========================//=========================//
152 //====================================================================================================================================//
153 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
154
2/2
✓ Branch 29 → 30 taken 2002 times.
✓ Branch 29 → 42 taken 1431 times.
3433 if(pid == particle::pi_plus) {
155
2/2
✓ Branch 30 → 31 taken 373 times.
✓ Branch 30 → 32 taken 1629 times.
2002 if(sec == 1) {
156 373 dp = ((-5.4904e-07) * phi * phi + (-1.4436e-05) * phi + (3.1534e-04)) * pp * pp + ((3.8231e-06) * phi * phi + (3.6582e-04) * phi + (-0.0046759)) * pp + ((-5.4913e-06) * phi * phi + (-4.0157e-04) * phi + (0.010767));
157 373 dp = dp + ((6.1103e-07) * phi * phi + (5.5291e-06) * phi + (-1.9120e-04)) * pp * pp + ((-3.2300e-06) * phi * phi + (1.5377e-05) * phi + (7.5279e-04)) * pp + ((2.1434e-06) * phi * phi + (-6.9572e-06) * phi + (-7.9333e-05));
158 373 dp = dp + ((-1.3049e-06) * phi * phi + (1.1295e-05) * phi + (4.5797e-04)) * pp * pp + ((9.3122e-06) * phi * phi + (-5.1074e-05) * phi + (-0.0030757)) * pp + ((-1.3102e-05) * phi * phi + (2.2153e-05) * phi + (0.0040938));
159 }
160
2/2
✓ Branch 32 → 33 taken 340 times.
✓ Branch 32 → 34 taken 1662 times.
2002 if(sec == 2) {
161 340 dp = ((-1.0087e-06) * phi * phi + (2.1319e-05) * phi + (7.8641e-04)) * pp * pp + ((6.7485e-06) * phi * phi + (7.3716e-05) * phi + (-0.0094591)) * pp + ((-1.1820e-05) * phi * phi + (-3.8103e-04) * phi + (0.018936));
162 340 dp = dp + ((8.8155e-07) * phi * phi + (-2.8257e-06) * phi + (-2.6729e-04)) * pp * pp + ((-5.4499e-06) * phi * phi + (3.8397e-05) * phi + (0.0015914)) * pp + ((6.8926e-06) * phi * phi + (-5.9386e-05) * phi + (-0.0021749));
163 340 dp = dp + ((-2.0147e-07) * phi * phi + (1.1061e-05) * phi + (3.8827e-04)) * pp * pp + ((4.9294e-07) * phi * phi + (-6.0257e-05) * phi + (-0.0022087)) * pp + ((9.8548e-07) * phi * phi + (5.9047e-05) * phi + (0.0022905));
164 }
165
2/2
✓ Branch 34 → 35 taken 313 times.
✓ Branch 34 → 36 taken 1689 times.
2002 if(sec == 3) {
166 313 dp = ((8.6722e-08) * phi * phi + (-1.7975e-05) * phi + (4.8118e-05)) * pp * pp + ((2.6273e-06) * phi * phi + (3.1453e-05) * phi + (-0.0015943)) * pp + ((-6.4463e-06) * phi * phi + (-5.8990e-05) * phi + (0.0041703));
167 313 dp = dp + ((9.6317e-07) * phi * phi + (-1.7659e-06) * phi + (-8.8318e-05)) * pp * pp + ((-5.1346e-06) * phi * phi + (8.3318e-06) * phi + (3.7723e-04)) * pp + ((3.9548e-06) * phi * phi + (-6.9614e-05) * phi + (2.1393e-04));
168 313 dp = dp + ((5.6438e-07) * phi * phi + (8.1678e-06) * phi + (-9.4406e-05)) * pp * pp + ((-3.9074e-06) * phi * phi + (-6.5174e-05) * phi + (5.4218e-04)) * pp + ((6.3198e-06) * phi * phi + (1.0611e-04) * phi + (-4.5749e-04));
169 }
170
2/2
✓ Branch 36 → 37 taken 328 times.
✓ Branch 36 → 38 taken 1674 times.
2002 if(sec == 4) {
171 328 dp = ((4.3406e-07) * phi * phi + (-4.9036e-06) * phi + (2.3064e-04)) * pp * pp + ((1.3624e-06) * phi * phi + (3.2907e-05) * phi + (-0.0034872)) * pp + ((-5.1017e-06) * phi * phi + (2.4593e-05) * phi + (0.0092479));
172 328 dp = dp + ((6.0218e-07) * phi * phi + (-1.4383e-05) * phi + (-3.1999e-05)) * pp * pp + ((-1.1243e-06) * phi * phi + (9.3884e-05) * phi + (-4.1985e-04)) * pp + ((-1.8808e-06) * phi * phi + (-1.2222e-04) * phi + (0.0014037));
173 328 dp = dp + ((-2.5490e-07) * phi * phi + (-8.5120e-07) * phi + (7.9109e-05)) * pp * pp + ((2.5879e-06) * phi * phi + (8.6108e-06) * phi + (-5.1533e-04)) * pp + ((-4.4521e-06) * phi * phi + (-1.7012e-05) * phi + (7.4848e-04));
174 }
175
2/2
✓ Branch 38 → 39 taken 353 times.
✓ Branch 38 → 40 taken 1649 times.
2002 if(sec == 5) {
176 353 dp = ((2.4292e-07) * phi * phi + (8.8741e-06) * phi + (2.9482e-04)) * pp * pp + ((3.7229e-06) * phi * phi + (7.3215e-06) * phi + (-0.0050685)) * pp + ((-1.1974e-05) * phi * phi + (-1.3043e-04) * phi + (0.0078836));
177 353 dp = dp + ((1.0867e-06) * phi * phi + (-7.7630e-07) * phi + (-4.4930e-05)) * pp * pp + ((-5.6564e-06) * phi * phi + (-1.3417e-05) * phi + (2.5224e-04)) * pp + ((6.8460e-06) * phi * phi + (9.0495e-05) * phi + (-4.6587e-04));
178 353 dp = dp + ((8.5720e-07) * phi * phi + (-6.7464e-06) * phi + (-4.0944e-05)) * pp * pp + ((-4.7370e-06) * phi * phi + (5.8808e-05) * phi + (1.9047e-04)) * pp + ((5.7404e-06) * phi * phi + (-1.1105e-04) * phi + (-1.9392e-04));
179 }
180
2/2
✓ Branch 40 → 41 taken 295 times.
✓ Branch 40 → 42 taken 1707 times.
2002 if(sec == 6) {
181 295 dp = ((2.1191e-06) * phi * phi + (-3.3710e-05) * phi + (2.5741e-04)) * pp * pp + ((-1.2915e-05) * phi * phi + (2.3753e-04) * phi + (-2.6882e-04)) * pp + ((2.2676e-05) * phi * phi + (-2.3115e-04) * phi + (-0.001283));
182 295 dp = dp + ((6.0270e-07) * phi * phi + (-6.8200e-06) * phi + (1.3103e-04)) * pp * pp + ((-1.8745e-06) * phi * phi + (3.8646e-05) * phi + (-8.8056e-04)) * pp + ((2.0885e-06) * phi * phi + (-3.4932e-05) * phi + (4.5895e-04));
183 295 dp = dp + ((4.7349e-08) * phi * phi + (-5.7528e-06) * phi + (-3.4097e-06)) * pp * pp + ((1.7731e-06) * phi * phi + (3.5865e-05) * phi + (-5.7881e-04)) * pp + ((-9.7008e-06) * phi * phi + (-4.1836e-05) * phi + (0.0035403));
184 }
185 }
186
187 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
188 //====================================================================================================================================//
189 //==================//==================// π- Corrections (Updated as of 01-13-2023) //==================//==================//
190 //====================================================================================================================================//
191 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
192
2/2
✓ Branch 42 → 43 taken 823 times.
✓ Branch 42 → 55 taken 2610 times.
3433 if(pid == particle::pi_minus) {
193
2/2
✓ Branch 43 → 44 taken 165 times.
✓ Branch 43 → 45 taken 658 times.
823 if(sec == 1) {
194
195 165 dp = (-9.2163E-07 * phi * phi + 3.1862E-06 * phi + 2.9805E-03) * pp * pp + (1.0435E-05 * phi * phi + -8.7298E-05 * phi + -1.7730E-02) * pp + -1.5154E-05 * phi * phi + -1.3716E-04 * phi + 2.2410E-02;
196 }
197
2/2
✓ Branch 45 → 46 taken 140 times.
✓ Branch 45 → 47 taken 683 times.
823 if(sec == 2) {
198
199 140 dp = (-1.9656E-06 * phi * phi + 9.7389E-05 * phi + 4.1250E-03) * pp * pp + (1.6439E-06 * phi * phi + -4.6007E-04 * phi + -1.9809E-02) * pp + 3.5794E-07 * phi * phi + 4.8250E-04 * phi + 1.7333E-02;
200 }
201
202
2/2
✓ Branch 47 → 48 taken 134 times.
✓ Branch 47 → 49 taken 689 times.
823 if(sec == 3) {
203
204 134 dp = (2.5351E-06 * phi * phi + 4.1043E-05 * phi + 3.1157E-03) * pp * pp + (-1.3573E-05 * phi * phi + -1.7609E-04 * phi + -1.6759E-02) * pp + 1.4647E-05 * phi * phi + 1.7484E-04 * phi + 1.3805E-02;
205 }
206
207
2/2
✓ Branch 49 → 50 taken 119 times.
✓ Branch 49 → 51 taken 704 times.
823 if(sec == 4) {
208
209 119 dp = (2.3500E-06 * phi * phi + -7.7894E-05 * phi + 4.4837E-03) * pp * pp + (-9.7915E-06 * phi * phi + 4.6576E-04 * phi + -2.6809E-02) * pp + 1.3819E-05 * phi * phi + -5.6017E-04 * phi + 3.0320E-02;
210 }
211
212
2/2
✓ Branch 51 → 52 taken 144 times.
✓ Branch 51 → 53 taken 679 times.
823 if(sec == 5) {
213
214 144 dp = (-2.1809E-06 * phi * phi + 2.4948E-05 * phi + 2.7995E-03) * pp * pp + (6.3908E-06 * phi * phi + -6.5122E-05 * phi + -1.7571E-02) * pp + -1.9146E-06 * phi * phi + -6.3799E-05 * phi + 2.0877E-02;
215 }
216
217
2/2
✓ Branch 53 → 54 taken 121 times.
✓ Branch 53 → 55 taken 702 times.
823 if(sec == 6) {
218
219 121 dp = (-9.3043E-06 * phi * phi + 6.2678E-05 * phi + 5.9660E-03) * pp * pp + (4.0581E-05 * phi * phi + -3.0537E-04 * phi + -3.1485E-02) * pp + -3.8345E-05 * phi * phi + 2.0267E-04 * phi + 3.3363E-02;
220 }
221 }
222
223 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
224 //====================================================================================================================================//
225 //=======================//=======================// All Proton Corrections //=======================//=======================//
226 //====================================================================================================================================//
227 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
228
2/2
✓ Branch 55 → 56 taken 276 times.
✓ Branch 55 → 68 taken 3157 times.
3433 if(pid == particle::proton) {
229
2/2
✓ Branch 56 → 57 taken 52 times.
✓ Branch 56 → 58 taken 224 times.
276 if(sec == 1) {
230 52 dp = ((1 + std::copysign(1, (pp - 1.4))) / 2) * ((4.4034e-03) * pp + (-0.01703)) + ((1 + std::copysign(1, -(pp - 1.4))) / 2) * ((-0.10898) * (pp - 1.4) * (pp - 1.4) + (-0.09574) * (pp - 1.4) + ((4.4034e-03) * 1.4 + (-0.01703)));
231 }
232
2/2
✓ Branch 58 → 59 taken 40 times.
✓ Branch 58 → 60 taken 236 times.
276 if(sec == 2) {
233 40 dp = ((1 + std::copysign(1, (pp - 1.5))) / 2) * ((0.01318) * pp + (-0.03403)) + ((1 + std::copysign(1, -(pp - 1.5))) / 2) * ((-0.09829) * (pp - 1.5) * (pp - 1.5) + (-0.0986) * (pp - 1.5) + ((0.01318) * 1.5 + (-0.03403)));
234 }
235
2/2
✓ Branch 60 → 61 taken 46 times.
✓ Branch 60 → 62 taken 230 times.
276 if(sec == 3) {
236 46 dp = ((1 + std::copysign(1, (pp - 1.05))) / 2) * ((-4.7052e-03) * pp + (1.2410e-03)) + ((1 + std::copysign(1, -(pp - 1.05))) / 2) * ((-0.22721) * (pp - 1.05) * (pp - 1.05) + (-0.09702) * (pp - 1.05) + ((-4.7052e-03) * 1.05 + (1.2410e-03)));
237 }
238
2/2
✓ Branch 62 → 63 taken 48 times.
✓ Branch 62 → 64 taken 228 times.
276 if(sec == 4) {
239 48 dp = ((1 + std::copysign(1, (pp - 1.4))) / 2) * ((-1.0900e-03) * pp + (-4.0573e-03)) + ((1 + std::copysign(1, -(pp - 1.4))) / 2) * ((-0.09236) * (pp - 1.4) * (pp - 1.4) + (-0.073) * (pp - 1.4) + ((-1.0900e-03) * 1.4 + (-4.0573e-03)));
240 }
241
2/2
✓ Branch 64 → 65 taken 50 times.
✓ Branch 64 → 66 taken 226 times.
276 if(sec == 5) {
242 50 dp = ((1 + std::copysign(1, (pp - 1.5))) / 2) * ((7.3965e-03) * pp + (-0.02428)) + ((1 + std::copysign(1, -(pp - 1.5))) / 2) * ((-0.09539) * (pp - 1.5) * (pp - 1.5) + (-0.09263) * (pp - 1.5) + ((7.3965e-03) * 1.5 + (-0.02428)));
243 }
244
2/2
✓ Branch 66 → 67 taken 40 times.
✓ Branch 66 → 68 taken 236 times.
276 if(sec == 6) {
245 40 dp = ((1 + std::copysign(1, (pp - 1.15))) / 2) * ((-7.6214e-03) * pp + (8.1014e-03)) + ((1 + std::copysign(1, -(pp - 1.15))) / 2) * ((-0.12718) * (pp - 1.15) * (pp - 1.15) + (-0.06626) * (pp - 1.15) + ((-7.6214e-03) * 1.15 + (8.1014e-03)));
246 }
247 }
248
249 3433 return dp / pp + 1;
250 }
251
252
253 double MomentumCorrection::CorrectionOutbending(vector_element_t const px, vector_element_t const py, vector_element_t const pz, int const sec, int const pid) const
254 {
255
256 // skip the correction if it's not defined
257 if(!(pid == particle::electron || pid == particle::pi_plus || pid == particle::pi_minus))
258 return 1.0;
259
260 // skip if the sector is unknown
261 if(!IsValidSector(sec))
262 return 1.0;
263
264 // Momentum Magnitude
265 double pp = sqrt(px * px + py * py + pz * pz);
266
267 // Initializing the correction factor
268 double dp = 0;
269
270 // Defining Phi Angle
271 double Phi = (180 / M_PI) * atan2(py, px);
272
273 // (Initial) Shift of the Phi Angle (done to realign sectors whose data is separated when plotted from ±180˚)
274 if(((sec == 4 || sec == 3) && Phi < 0) || (sec > 4 && Phi < 90)) {
275 Phi += 360;
276 }
277
278 // Getting Local Phi Angle
279 double PhiLocal = Phi - (sec - 1) * 60;
280
281 // Applying Shift Functions to Phi Angles (local shifted phi = phi)
282 double phi = PhiLocal;
283 // For Electron Shift
284 if(pid == particle::electron) {
285 phi = PhiLocal - 30 / pp;
286 }
287 // For π+ Pion/Proton Shift
288 if(pid == particle::pi_plus || pid == particle::proton) {
289 phi = PhiLocal + (32 / (pp - 0.05));
290 }
291 // For π- Pion Shift
292 if(pid == particle::pi_minus) {
293 phi = PhiLocal - (32 / (pp - 0.05));
294 }
295
296 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
297 //=======================//=======================// Electron Corrections //=======================//=======================//
298 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
299 if(pid == particle::electron) {
300 if(sec == 1) {
301 dp = ((1.3189e-06) * phi * phi + (4.26057e-05) * phi + (-0.002322628)) * pp * pp + ((-1.1409e-05) * phi * phi + (2.2188e-05) * phi + (0.02878927)) * pp + ((2.4950e-05) * phi * phi + (1.6170e-06) * phi + (-0.061816275));
302 }
303 if(sec == 2) {
304 dp = ((-2.9240e-07) * phi * phi + (3.2448e-07) * phi + (-0.001848308)) * pp * pp + ((4.4500e-07) * phi * phi + (4.76324e-04) * phi + (0.02219469)) * pp + ((6.9220e-06) * phi * phi + (-0.00153517) * phi + (-0.0479058));
305 }
306 if(sec == 3) {
307 dp = ((2.71911e-06) * phi * phi + (1.657148e-05) * phi + (-0.001822211)) * pp * pp + ((-4.96814e-05) * phi * phi + (-3.761117e-04) * phi + (0.02564148)) * pp + ((1.97748e-04) * phi * phi + (9.58259e-04) * phi + (-0.05818292));
308 }
309 if(sec == 4) {
310 dp = ((1.90966e-06) * phi * phi + (-2.4761e-05) * phi + (-0.00231562)) * pp * pp + ((-2.3927e-05) * phi * phi + (2.25262e-04) * phi + (0.0291831)) * pp + ((8.0515e-05) * phi * phi + (-6.42098e-04) * phi + (-0.06159197));
311 }
312 if(sec == 5) {
313 dp = ((-3.6760323e-06) * phi * phi + (4.04398e-05) * phi + (-0.0021967515)) * pp * pp + ((4.90857e-05) * phi * phi + (-4.37437e-04) * phi + (0.02494339)) * pp + ((-1.08257e-04) * phi * phi + (0.00146111) * phi + (-0.0648485));
314 }
315 if(sec == 6) {
316 dp = ((-6.2488e-08) * phi * phi + (2.23173e-05) * phi + (-0.00227522)) * pp * pp + ((1.8372e-05) * phi * phi + (-7.5227e-05) * phi + (0.032636)) * pp + ((-6.6566e-05) * phi * phi + (-2.4450e-04) * phi + (-0.072293));
317 }
318 }
319
320 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
321 //=========================//=========================// π+ Corrections //=========================//=========================//
322 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
323 if(pid == particle::pi_plus) {
324 if(sec == 1) {
325 dp = ((-1.7334e-06) * phi * phi + (1.45112e-05) * phi + (0.00150721)) * pp * pp + ((6.6234e-06) * phi * phi + (-4.81191e-04) * phi + (-0.0138695)) * pp + ((-3.23625e-06) * phi * phi + (2.79751e-04) * phi + (0.027726));
326 }
327 if(sec == 2) {
328 dp = ((-4.475464e-06) * phi * phi + (-4.11573e-05) * phi + (0.00204557)) * pp * pp + ((2.468278e-05) * phi * phi + (9.3590e-05) * phi + (-0.015399)) * pp + ((-1.61547e-05) * phi * phi + (-2.4206e-04) * phi + (0.0231743));
329 }
330 if(sec == 3) {
331 dp = ((-8.0374e-07) * phi * phi + (2.8728e-06) * phi + (0.00152163)) * pp * pp + ((5.1347e-06) * phi * phi + (3.71709e-04) * phi + (-0.0165735)) * pp + ((4.0105e-06) * phi * phi + (-5.289869e-04) * phi + (0.02175395));
332 }
333 if(sec == 4) {
334 dp = ((-3.8790e-07) * phi * phi + (-4.78445e-05) * phi + (0.002324725)) * pp * pp + ((6.80543e-06) * phi * phi + (5.69358e-04) * phi + (-0.0199162)) * pp + ((-1.30264e-05) * phi * phi + (-5.91606e-04) * phi + (0.03202088));
335 }
336 if(sec == 5) {
337 dp = ((2.198518e-06) * phi * phi + (-1.52535e-05) * phi + (0.001187761)) * pp * pp + ((-1.000264e-05) * phi * phi + (1.63976e-04) * phi + (-0.01429673)) * pp + ((9.4962e-06) * phi * phi + (-3.86691e-04) * phi + (0.0303695));
338 }
339 if(sec == 6) {
340 dp = ((-3.92944e-07) * phi * phi + (1.45848e-05) * phi + (0.00120668)) * pp * pp + ((3.7899e-06) * phi * phi + (-1.98219e-04) * phi + (-0.0131312)) * pp + ((-3.9961e-06) * phi * phi + (-1.32883e-04) * phi + (0.0294497));
341 }
342 }
343
344 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
345 //=======================//=======================// π- Corrections //=======================//=======================//
346 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
347 if(pid == particle::pi_minus) {
348 if(sec == 1) {
349 dp = (7.8044E-06 * phi * phi + -9.4703E-05 * phi + 4.6696E-03) * pp * pp + (-3.4668E-05 * phi * phi + 6.2280E-04 * phi + -2.4273E-02) * pp + 2.3566E-05 * phi * phi + -5.8519E-04 * phi + 3.9226E-02;
350 }
351 if(sec == 2) {
352 dp = (-4.6611E-06 * phi * phi + -8.1637E-05 * phi + 7.5013E-03) * pp * pp + (1.7616E-05 * phi * phi + 3.5439E-04 * phi + -3.7122E-02) * pp + -1.6286E-05 * phi * phi + -2.6545E-04 * phi + 4.5659E-02;
353 }
354 if(sec == 3) {
355 dp = (4.5270E-06 * phi * phi + 2.2578E-04 * phi + 5.9214E-03) * pp * pp + (-1.6419E-05 * phi * phi + -8.1776E-04 * phi + -3.2776E-02) * pp + 1.3734E-05 * phi * phi + 6.6125E-04 * phi + 4.5784E-02;
356 }
357 if(sec == 4) {
358 dp = (-1.3141E-06 * phi * phi + 1.9648E-04 * phi + 7.6109E-03 - 0.006) * pp * pp + (8.0912E-06 * phi * phi + -8.2672E-04 * phi + -4.0495E-02 + 0.03) * pp + -3.1380E-06 * phi * phi + 6.2211E-04 * phi + 5.3361E-02 - 0.04;
359 }
360 if(sec == 5) {
361 dp = (-5.4065E-06 * phi * phi + -1.6325E-05 * phi + 1.2269E-02 - 0.002) * pp * pp + (1.9512E-05 * phi * phi + 1.0228E-04 * phi + -6.2351E-02 + 0.01) * pp + -9.5023E-06 * phi * phi + -3.7997E-05 * phi + 7.1061E-02 - 0.02;
362 }
363 if(sec == 6) {
364 dp = (-1.1882E-05 * phi * phi + 2.0101E-04 * phi + 1.1635E-02 - 0.01) * pp * pp + (5.8488E-05 * phi * phi + -6.4709E-04 * phi + -5.3833E-02 + 0.05) * pp + -4.4462E-05 * phi * phi + 3.7529E-04 * phi + 6.2130E-02 - 0.06;
365 }
366 }
367
368 return dp / pp + 1;
369 }
370
371
372 9922 double MomentumCorrection::EnergyLossInbending(vector_element_t const px, vector_element_t const py, vector_element_t const pz, int const pid) const
373 {
374
375 // The following code is for the Energy Loss Corrections for the proton
376
2/2
✓ Branch 2 → 3 taken 472 times.
✓ Branch 2 → 7 taken 9450 times.
9922 if(pid != particle::proton)
377 return 1.0;
378
379 double dE_loss = 0;
380 472 auto pro = sqrt(px * px + py * py + pz * pz);
381 472 auto proth = atan2(sqrt(px * px + py * py), pz) * (180 / M_PI);
382
383 // Inbending Energy Loss Correction //
384
2/2
✓ Branch 3 → 4 taken 196 times.
✓ Branch 3 → 5 taken 276 times.
472 if(proth < 27) {
385 196 dE_loss = exp(-2.739 - 3.932 * pro) + 0.002907;
386 }
387 else {
388 276 dE_loss = exp(-1.2 - 4.228 * pro) + 0.007502;
389 }
390 472 return (pro + dE_loss) / pro;
391 }
392
393
394 double MomentumCorrection::EnergyLossOutbending(vector_element_t const px, vector_element_t const py, vector_element_t const pz, int const pid) const
395 {
396
397 // The following code is for the Energy Loss Corrections for the proton
398 if(pid != particle::proton)
399 return 1.0;
400
401 double dE_loss = 0;
402 auto pro = sqrt(px * px + py * py + pz * pz);
403 auto proth = atan2(sqrt(px * px + py * py), pz) * (180 / M_PI);
404
405 // Outbending Energy Loss Correction //
406 if(proth > 27) {
407 dE_loss = exp(-1.871 - 3.063 * pro) + 0.007517;
408 }
409 return (pro + dE_loss) / pro;
410 }
411
412
413 4 void MomentumCorrection::Stop()
414 {
415 4 }
416
417 }
418