GCC Code Coverage Report


Directory: ./
File: src/iguana/algorithms/clas12/PhotonGBTFilter/Algorithm.h
Date: 2025-01-05 09:03:17
Exec Total Coverage
Lines: 2 17 11.8%
Functions: 3 4 75.0%
Branches: 25 88 28.4%

Line Branch Exec Source
1 #pragma once
2
3 #include "iguana/algorithms/Algorithm.h"
4 #include "iguana/algorithms/TypeDefs.h"
5 #include "models/RGA_inbending_pass1.cpp"
6 #include "models/RGA_outbending_pass1.cpp"
7 #include "models/RGA_inbending_pass2.cpp"
8 #include "models/RGA_outbending_pass2.cpp"
9 #include "models/RGC_Summer2022_pass1.cpp"
10
11 #include <Math/Vector3D.h>
12 #include <Math/VectorUtil.h>
13
14 namespace iguana::clas12 {
15
16 ///
17 /// @brief_algo Filter the `REC::Particle` photons using pretrained GBT models
18 ///
19 /// For each photon (labeled the photon of interest or POI), we obtain its intrinsic features (energy, angle, pcal edep, etc.) and features corresponding to its nearest neighbors (angle of proximity, energy difference, etc.). This requires the reading of both the REC::Particle and REC::Calorimeter banks. An input std::vector<float> is produced and passed to the pretrained GBT models, which yield a classification score between 0 and 1. An option variable `threshold` then determines the minimum photon `p-value` to survive the cut.
20 ///
21 /// @begin_doc_algo{clas12::PhotonGBTFilter | Filter}
22 /// @input_banks{REC::Particle, REC::Calorimeter, RUN::config}
23 /// @output_banks{REC::Particle}
24 /// @end_doc
25 ///
26 /// @begin_doc_config
27 /// @config_param{pass | int | cook type}
28 /// @config_param{threshold | double | minimum value to qualify a photon as "true"}
29 /// @end_doc
30 class PhotonGBTFilter : public Algorithm
31 {
32
33
25/88
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✓ Branch 10 taken 32 times.
✓ Branch 11 taken 2 times.
✓ Branch 12 taken 32 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 2 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 2 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 2 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 2 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 2 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 2 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 2 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 2 times.
✗ Branch 31 not taken.
✓ Branch 32 taken 2 times.
✗ Branch 33 not taken.
✓ Branch 34 taken 2 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 2 times.
✗ Branch 37 not taken.
✓ Branch 38 taken 2 times.
✗ Branch 39 not taken.
✓ Branch 40 taken 2 times.
✗ Branch 41 not taken.
✓ Branch 42 taken 2 times.
✗ Branch 43 not taken.
✓ Branch 44 taken 2 times.
✗ Branch 45 not taken.
✓ Branch 46 taken 2 times.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
80 DEFINE_IGUANA_ALGORITHM(PhotonGBTFilter, clas12::PhotonGBTFilter)
34
35 public:
36
37 void Start(hipo::banklist& banks) override;
38 void Run(hipo::banklist& banks) const override;
39 void Stop() override;
40
41 /// Applies forward detector cut using REC::Particle Theta
42 /// @param theta lab angle of the particle with respect to the beam direction (radians)
43 /// @returns `true` if the particle's theta is within the forward detector coverage, `false` otherwise
44 bool ForwardDetectorFilter(float const theta) const;
45
46 private:
47
48 struct calo_row_data {
49 double pcal_x = 0;
50 double pcal_y = 0;
51 double pcal_z = 0;
52 double ecin_x = 0;
53 double ecin_y = 0;
54 double ecin_z = 0;
55 double ecout_x = 0;
56 double ecout_y = 0;
57 double ecout_z = 0;
58 double pcal_e = 0;
59 double pcal_m2u = 0;
60 double pcal_m2v = 0;
61 double ecin_e = 0;
62 double ecin_m2u = 0;
63 double ecin_m2v = 0;
64 double ecout_e = 0;
65 double ecout_m2u = 0;
66 double ecout_m2v = 0;
67 };
68
69 /// Applies pid purity cuts to photons, compatible to how the GBT models are trained
70 /// @param E energy of the photon
71 /// @param Epcal energy the photon has deposited in the pre-shower calorimeter
72 /// @param theta lab angle of the photon with respect to the beam direction (radians)
73 /// @returns `true` if the photon passes the pid purity cuts, `false` otherwise
74 bool PidPurityPhotonFilter(float const E, float const Epcal, float const theta) const;
75
76 /// Classifies the photon for a given event as signal or background
77 /// @param particleBank the REC::Particle hipo bank
78 /// @param caloBank the REC::Calorimeter hipo bank
79 /// @param calo_map the std::map<> of calorimeter data for the event, indexed by pindex
80 /// @param row the row corresponding to the photon being classified
81 /// @param runnum the current run number
82 /// @returns `true` if the photon is to be considered signal, otherwise `false`
83 bool Filter(hipo::bank const &particleBank, hipo::bank const &caloBank, std::map<int, PhotonGBTFilter::calo_row_data> calo_map, int const row, int const runnum) const;
84
85
86 /// Calls the appropriate CatBoost model for the given run group, classifying the photon of interest
87 /// @param input_data the input features of the model
88 /// @param runnum the run number associated to the event
89 /// @returns `true` if the
90 bool ClassifyPhoton(std::vector<float> const &input_data, int const runnum) const;
91
92
93 /// Gets calorimeter data for particles in the event
94 /// @param bank the bank to get data from
95 /// @returns a map with keys as particle indices (pindex) and values as calo_row_data structs
96 std::map<int, PhotonGBTFilter::calo_row_data> GetCaloMap(hipo::bank const &bank) const;
97
98
99 /// Gets the calorimeter vector for a particle in the event
100 /// @param crd data struct of a single REC::Calorimeter's row data
101 /// @returns a ROOT::Math::XYZVector with the coordinates of the particle in the calorimeter
102 ROOT::Math::XYZVector GetParticleCaloVector(PhotonGBTFilter::calo_row_data calo_row) const;
103
104
105 /// Gets the mass of a particle given its PID
106 /// @param pid the particle ID to get the mass for
107 /// @returns the mass of the particle in GeV; returns -1.0 if the PID is not recognized
108 double GetMass(int pid) const;
109
110
111 /// Gets the model function for the run number
112 /// @param runnum the run of the associated event
113 /// @returns GBT function for the run period
114 std::function<double(std::vector<float> const &)> getModelFunction(int runnum) const;
115
116 /// `hipo::banklist`
117 hipo::banklist::size_type b_particle;
118 hipo::banklist::size_type b_calorimeter;
119 hipo::banklist::size_type b_config; // RUN::config
120
121 /// Threshold value for model predictions
122 double o_threshold = 0.78;
123
124 /// Integer for the event reconstruction pass
125 int o_pass = 1;
126
127 /// Map for the GBT Models to use depending on pass and run number
128 const std::map<std::tuple<int, int, int>, std::function<double(std::vector<float> const &)>> modelMap = {
129 {{5032, 5332, 1}, [](std::vector<float> const &data) { return ApplyCatboostModel_RGA_inbending_pass1(data); }}, // Fall2018 RGA Inbending
130 {{5032, 5332, 2}, [](std::vector<float> const &data) { return ApplyCatboostModel_RGA_inbending_pass2(data); }}, // Fall2018 RGA Inbending
131 {{5333, 5666, 1}, [](std::vector<float> const &data) { return ApplyCatboostModel_RGA_outbending_pass1(data); }}, // Fall2018 RGA Outbending
132 {{5333, 5666, 2}, [](std::vector<float> const &data) { return ApplyCatboostModel_RGA_outbending_pass2(data); }}, // Fall2018 RGA Outbending
133 2654 {{6616, 6783, 1}, [](std::vector<float> const &data) { return ApplyCatboostModel_RGA_inbending_pass1(data); }}, // Spring2019 RGA Inbending
134 {{6616, 6783, 2}, [](std::vector<float> const &data) { return ApplyCatboostModel_RGA_inbending_pass2(data); }}, // Spring2019 RGA Inbending
135 {{6156, 6603, 1}, [](std::vector<float> const &data) { return ApplyCatboostModel_RGA_inbending_pass1(data); }}, // Spring2019 RGB Inbending
136 {{6156, 6603, 2}, [](std::vector<float> const &data) { return ApplyCatboostModel_RGA_inbending_pass2(data); }}, // Spring2019 RGB Inbending
137 {{11093, 11283, 1}, [](std::vector<float> const &data) { return ApplyCatboostModel_RGA_outbending_pass1(data); }}, // Fall2019 RGB Outbending
138 {{11093, 11283, 2}, [](std::vector<float> const &data) { return ApplyCatboostModel_RGA_outbending_pass2(data); }}, // Fall2019 RGB Outbending
139 {{11284, 11300, 1}, [](std::vector<float> const &data) { return ApplyCatboostModel_RGA_inbending_pass1(data); }}, // Fall2019 RGB BAND Inbending
140 {{11284, 11300, 2}, [](std::vector<float> const &data) { return ApplyCatboostModel_RGA_inbending_pass2(data); }}, // Fall2019 RGB BAND Inbending
141 {{11323, 11571, 1}, [](std::vector<float> const &data) { return ApplyCatboostModel_RGA_inbending_pass1(data); }}, // Spring2020 RGB Inbending
142 {{11323, 11571, 2}, [](std::vector<float> const &data) { return ApplyCatboostModel_RGA_inbending_pass2(data); }}, // Spring2020 RGB Inbending
143 {{16042, 16772, 1}, [](std::vector<float> const &data) { return ApplyCatboostModel_RGC_Summer2022_pass1(data); }}, // Summer2022 RGC Inbending
144 {{16042, 16772, 2}, [](std::vector<float> const &data) { return ApplyCatboostModel_RGC_Summer2022_pass1(data); }} // Summer2022 RGC Inbending (no pass2 currently)
145 };
146 };
147
148 }
149