GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 75.0% 3 / 0 / 4
Functions: 100.0% 3 / 0 / 3
Branches: 42.9% 6 / 0 / 14

src/iguana/algorithms/clas12/PhotonGBTFilter/Algorithm.h
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 /// @doc_config{clas12/PhotonGBTFilter}
17 class PhotonGBTFilter : public Algorithm
18 {
19
20
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)
21
22 private: // hooks
23 void ConfigHook() override;
24 void StartHook(hipo::banklist& banks) override;
25 bool RunHook(hipo::banklist& banks) const override;
26
27 public:
28
29 /// @run_function
30 /// @param [in,out] particleBank `REC::Particle`, which will be filtered
31 /// @param [in] caloBank `REC::Calorimeter`
32 /// @param [in] configBank `RUN::config`
33 /// @returns `false` if all particles are filtered out
34 bool Run(
35 hipo::bank& particleBank,
36 hipo::bank const& caloBank,
37 hipo::bank const& configBank) const;
38
39 /// Applies forward detector cut using REC::Particle Theta
40 /// @param theta lab angle of the particle with respect to the beam direction (radians)
41 /// @returns `true` if the particle's theta is within the forward detector coverage, `false` otherwise
42 bool ForwardDetectorFilter(float const theta) const;
43
44 private:
45
46 struct calo_row_data {
47 double pcal_x = 0;
48 double pcal_y = 0;
49 double pcal_z = 0;
50 double ecin_x = 0;
51 double ecin_y = 0;
52 double ecin_z = 0;
53 double ecout_x = 0;
54 double ecout_y = 0;
55 double ecout_z = 0;
56 double pcal_e = 0;
57 double pcal_m2u = 0;
58 double pcal_m2v = 0;
59 double ecin_e = 0;
60 double ecin_m2u = 0;
61 double ecin_m2v = 0;
62 double ecout_e = 0;
63 double ecout_m2u = 0;
64 double ecout_m2v = 0;
65 };
66
67 /// Applies pid purity cuts to photons, compatible to how the GBT models are trained
68 /// @param E energy of the photon
69 /// @param Epcal energy the photon has deposited in the pre-shower calorimeter
70 /// @param theta lab angle of the photon with respect to the beam direction (radians)
71 /// @returns `true` if the photon passes the pid purity cuts, `false` otherwise
72 bool PidPurityPhotonFilter(float const E, float const Epcal, float const theta) const;
73
74 /// Classifies the photon for a given event as signal or background
75 /// @param particleBank the REC::Particle hipo bank
76 /// @param caloBank the REC::Calorimeter hipo bank
77 /// @param calo_map the std::map<> of calorimeter data for the event, indexed by pindex
78 /// @param row the row corresponding to the photon being classified
79 /// @param runnum the current run number
80 /// @returns `true` if the photon is to be considered signal, otherwise `false`
81 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;
82
83
84 /// Calls the appropriate CatBoost model for the given run group, classifying the photon of interest
85 /// @param input_data the input features of the model
86 /// @param runnum the run number associated to the event
87 /// @returns `true` if the
88 bool ClassifyPhoton(std::vector<float> const& input_data, int const runnum) const;
89
90
91 /// Gets calorimeter data for particles in the event
92 /// @param bank the bank to get data from
93 /// @returns a map with keys as particle indices (pindex) and values as calo_row_data structs
94 std::map<int, PhotonGBTFilter::calo_row_data> GetCaloMap(hipo::bank const& bank) const;
95
96
97 /// Gets the calorimeter vector for a particle in the event
98 /// @param crd data struct of a single REC::Calorimeter's row data
99 /// @returns a ROOT::Math::XYZVector with the coordinates of the particle in the calorimeter
100 ROOT::Math::XYZVector GetParticleCaloVector(PhotonGBTFilter::calo_row_data calo_row) const;
101
102 /// Gets the model function for the run number
103 /// @param runnum the run of the associated event
104 /// @returns GBT function for the run period
105 std::function<double(std::vector<float> const&)> getModelFunction(int runnum) const;
106
107 /// `hipo::banklist`
108 hipo::banklist::size_type b_particle;
109 hipo::banklist::size_type b_calorimeter;
110 hipo::banklist::size_type b_config; // RUN::config
111
112 /// Threshold value for model predictions
113 double o_threshold = 0.78;
114
115 /// Integer for the event reconstruction pass
116 int o_pass = 1;
117
118 /// Map for the GBT Models to use depending on pass and run number
119 static std::map<std::tuple<int, int, int>, std::function<double(std::vector<float> const&)>> const modelMap;
120 };
121
122 }
123