GCC Code Coverage Report


Directory: ./
File: src/iguana/algorithms/clas12/PhotonGBTFilter/Algorithm.h
Date: 2025-11-25 17:57:04
Coverage Exec Excl Total
Lines: 75.0% 3 0 4
Functions: 100.0% 3 0 3
Branches: 42.9% 6 0 14

Line Branch Exec Source
1 #pragma once
2
3 #include "iguana/algorithms/Algorithm.h"
4
5 #include <Math/Vector3D.h>
6 #include <Math/VectorUtil.h>
7
8 namespace iguana::clas12 {
9
10 ///
11 /// @algo_brief{Filter the `REC::Particle` photons using pretrained GBT models}
12 /// @algo_type_filter
13 ///
14 /// 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.
15 ///
16 /// @begin_doc_config{clas12/PhotonGBTFilter}
17 /// @config_param{pass | int | cook type}
18 /// @config_param{threshold | double | minimum value to qualify a photon as "true"}
19 /// @end_doc
20 class PhotonGBTFilter : public Algorithm
21 {
22
23
6/14
✓ Branch 2 → 3 taken 2 times.
✗ Branch 2 → 6 not taken.
✗ Branch 5 → 7 not taken.
✓ Branch 5 → 8 taken 2 times.
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 32 not taken.
✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 17 not taken.
✓ Branch 17 → 18 taken 2 times.
✗ Branch 17 → 40 not taken.
✓ Branch 24 → 25 taken 2 times.
✗ Branch 24 → 40 not taken.
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 39 not taken.
16 DEFINE_IGUANA_ALGORITHM(PhotonGBTFilter, clas12::PhotonGBTFilter)
24
25 public:
26
27 void Start(hipo::banklist& banks) override;
28 bool Run(hipo::banklist& banks) const override;
29 void Stop() override;
30
31 /// @run_function
32 /// @param [in,out] particleBank `REC::Particle`, which will be filtered
33 /// @param [in] caloBank `REC::Calorimeter`
34 /// @param [in] configBank `RUN::config`
35 /// @returns `false` if all particles are filtered out
36 bool Run(
37 hipo::bank& particleBank,
38 hipo::bank const& caloBank,
39 hipo::bank const& configBank) const;
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 /// Gets the model function for the run number
105 /// @param runnum the run of the associated event
106 /// @returns GBT function for the run period
107 std::function<double(std::vector<float> const&)> getModelFunction(int runnum) const;
108
109 /// `hipo::banklist`
110 hipo::banklist::size_type b_particle;
111 hipo::banklist::size_type b_calorimeter;
112 hipo::banklist::size_type b_config; // RUN::config
113
114 /// Threshold value for model predictions
115 double o_threshold = 0.78;
116
117 /// Integer for the event reconstruction pass
118 int o_pass = 1;
119
120 /// Map for the GBT Models to use depending on pass and run number
121 static std::map<std::tuple<int, int, int>, std::function<double(std::vector<float> const&)>> const modelMap;
122 };
123
124 }
125