GCC Code Coverage Report


Directory: ./
File: src/iguana/algorithms/physics/Depolarization/Algorithm.cc
Date: 2025-03-24 18:50:00
Exec Total Coverage
Lines: 45 57 78.9%
Functions: 4 4 100.0%
Branches: 21 40 52.5%

Line Branch Exec Source
1 #include "Algorithm.h"
2
3 namespace iguana::physics {
4
5 REGISTER_IGUANA_ALGORITHM(Depolarization, "physics::Depolarization");
6
7 2 void Depolarization::Start(hipo::banklist& banks)
8 {
9
1/2
✓ Branch 0 (3→4) taken 2 times.
✗ Branch 1 (3→17) not taken.
2 b_inc_kin = GetBankIndex(banks, "physics::InclusiveKinematics");
10
11 // create the output bank
12 // FIXME: generalize the groupid and itemid
13
1/2
✓ Branch 0 (6→7) taken 2 times.
✗ Branch 1 (6→19) not taken.
2 auto result_schema = CreateBank(banks, b_result, GetClassName());
14
1/2
✓ Branch 0 (8→9) taken 2 times.
✗ Branch 1 (8→21) not taken.
2 i_epsilon = result_schema.getEntryOrder("epsilon");
15
1/2
✓ Branch 0 (9→10) taken 2 times.
✗ Branch 1 (9→21) not taken.
2 i_A = result_schema.getEntryOrder("A");
16
1/2
✓ Branch 0 (10→11) taken 2 times.
✗ Branch 1 (10→21) not taken.
2 i_B = result_schema.getEntryOrder("B");
17
1/2
✓ Branch 0 (11→12) taken 2 times.
✗ Branch 1 (11→21) not taken.
2 i_C = result_schema.getEntryOrder("C");
18
1/2
✓ Branch 0 (12→13) taken 2 times.
✗ Branch 1 (12→21) not taken.
2 i_V = result_schema.getEntryOrder("V");
19
2/4
✓ Branch 0 (13→14) taken 2 times.
✗ Branch 1 (13→21) not taken.
✓ Branch 2 (14→15) taken 2 times.
✗ Branch 3 (14→21) not taken.
2 i_W = result_schema.getEntryOrder("W");
20
21 2 m_log->Warn("the kinematic calculations in this algorithm need to be cross checked; use this algorithm at your own risk!");
22 2 }
23
24 ///////////////////////////////////////////////////////////////////////////////
25
26 2000 void Depolarization::Run(hipo::banklist& banks) const
27 {
28
1/2
✓ Branch 0 (3→4) taken 2000 times.
✗ Branch 1 (3→41) not taken.
4000 auto& inc_kin_bank = GetBank(banks, b_inc_kin, "physics::InclusiveKinematics");
29
1/2
✓ Branch 0 (6→7) taken 2000 times.
✗ Branch 1 (6→43) not taken.
4000 auto& result_bank = GetBank(banks, b_result, GetClassName());
30
31
1/2
✓ Branch 0 (9→10) taken 2000 times.
✗ Branch 1 (9→45) not taken.
2000 ShowBank(inc_kin_bank, Logger::Header("INPUT INCLUSIVE KINEMATICS"));
32
33 // set `result_bank` rows and rowlist to match those of `inc_kin_bank`
34 2000 auto const& inc_kin_bank_rowlist = inc_kin_bank.getRowList();
35 2000 result_bank.setRows(inc_kin_bank.getRows());
36 2000 result_bank.getMutableRowList().setList(inc_kin_bank_rowlist);
37
38 // loop over ALL `inc_kin_bank`'s rows; calculate depolarization for only the rows
39 // that are in its current rowlist, and zero the rest
40
2/2
✓ Branch 0 (36→16) taken 234 times.
✓ Branch 1 (36→37) taken 2000 times.
2234 for(int row = 0; row < inc_kin_bank.getRows(); row++) {
41
1/2
✓ Branch 0 (16→17) taken 234 times.
✗ Branch 1 (16→29) not taken.
234 if(std::find(inc_kin_bank_rowlist.begin(), inc_kin_bank_rowlist.end(), row) != inc_kin_bank_rowlist.end()) {
42 234 auto result_vars = Compute(
43 inc_kin_bank.getDouble("Q2", row),
44 inc_kin_bank.getDouble("x", row),
45 inc_kin_bank.getDouble("y", row),
46 inc_kin_bank.getDouble("targetM", row));
47 234 result_bank.putDouble(i_epsilon, row, result_vars.epsilon);
48 234 result_bank.putDouble(i_A, row, result_vars.A);
49 234 result_bank.putDouble(i_B, row, result_vars.B);
50 234 result_bank.putDouble(i_C, row, result_vars.C);
51 234 result_bank.putDouble(i_V, row, result_vars.V);
52 234 result_bank.putDouble(i_W, row, result_vars.W);
53 }
54 else {
55 result_bank.putDouble(i_epsilon, row, 0);
56 result_bank.putDouble(i_A, row, 0);
57 result_bank.putDouble(i_B, row, 0);
58 result_bank.putDouble(i_C, row, 0);
59 result_bank.putDouble(i_V, row, 0);
60 result_bank.putDouble(i_W, row, 0);
61 }
62 }
63
64
1/2
✓ Branch 0 (38→39) taken 2000 times.
✗ Branch 1 (38→47) not taken.
2000 ShowBank(result_bank, Logger::Header("CREATED BANK"));
65 2000 }
66
67 ///////////////////////////////////////////////////////////////////////////////
68
69 234 DepolarizationVars Depolarization::Compute(double const Q2, double const x, double const y, double const targetM) const
70 {
71 DepolarizationVars const zero_result{
72 .epsilon = 0,
73 .A = 0,
74 .B = 0,
75 .C = 0,
76 .V = 0,
77 .W = 0
78 };
79
80 // calculate gamma
81
1/2
✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→5) taken 234 times.
234 if(Q2 <= 0) {
82 m_log->Warn("Q2 = {} <= 0", Q2);
83 return zero_result;
84 }
85 234 auto gamma = 2 * targetM * x / std::sqrt(Q2);
86
87 // calculate epsilon
88
1/2
✗ Branch 0 (5→6) not taken.
✓ Branch 1 (5→8) taken 234 times.
234 auto epsilon_denom = 1 - y + y*y/2 + std::pow(gamma*y,2) / 4;
89
1/2
✗ Branch 0 (5→6) not taken.
✓ Branch 1 (5→8) taken 234 times.
234 if(!(std::abs(epsilon_denom) > 0)) {
90 m_log->Warn("epsilon denominator is zero");
91 return zero_result;
92 }
93 234 auto epsilon = ( 1 - y - std::pow(gamma*y,2)/4 ) / epsilon_denom;
94
95 // calculate A
96
1/2
✗ Branch 0 (8→9) not taken.
✓ Branch 1 (8→11) taken 234 times.
234 auto A_denom = 2 - 2*epsilon;
97
1/2
✗ Branch 0 (8→9) not taken.
✓ Branch 1 (8→11) taken 234 times.
234 if(!(std::abs(A_denom) > 0)) {
98 m_log->Warn("depol. factor A denominator is zero");
99 return zero_result;
100 }
101 234 auto A = y*y / A_denom;
102
103 // calculate B,C,V,W
104 return {
105 .epsilon = epsilon,
106 .A = A,
107 234 .B = A * epsilon,
108 234 .C = A * std::sqrt(1-epsilon*epsilon),
109 234 .V = A * std::sqrt(2*epsilon*(1+epsilon)),
110 234 .W = A * std::sqrt(2*epsilon*(1-epsilon))
111 234 };
112 }
113
114 ///////////////////////////////////////////////////////////////////////////////
115
116 1 void Depolarization::Stop()
117 {
118 1 }
119
120 }
121