GCC Code Coverage Report


Directory: ./
File: src/iguana/algorithms/clas12/PhotonGBTFilter/Validator.cc
Date: 2025-01-05 09:03:17
Exec Total Coverage
Lines: 100 100 100.0%
Functions: 6 6 100.0%
Branches: 87 164 53.0%

Line Branch Exec Source
1 #include "Validator.h"
2 #include "Algorithm.h"
3 namespace iguana::clas12 {
4
5 REGISTER_IGUANA_VALIDATOR(PhotonGBTFilterValidator);
6
7 1 void PhotonGBTFilterValidator::Start(hipo::banklist& banks)
8 {
9 // define the algorithm sequence
10 2 m_algo_seq = std::make_unique<AlgorithmSequence>();
11
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 m_algo_seq->Add("clas12::PhotonGBTFilter");
12
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 m_algo_seq->Add("clas12::EventBuilderFilter");
13
4/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
3 m_algo_seq->SetOption<std::vector<int>>("clas12::EventBuilderFilter", "pids", u_pdg_list);
14 1 m_algo_seq->Start(banks);
15
16 // get bank indices
17
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 b_particle = GetBankIndex(banks, "REC::Particle");
18
19 // set an output file
20 1 auto output_dir = GetOutputDirectory();
21
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(output_dir) {
22
3/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2 m_output_file_basename = output_dir.value() + "/photon_gbt";
23
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 m_output_file = new TFile(m_output_file_basename + ".root", "RECREATE");
24 }
25
26
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 InitializeHistograms();
27 1 }
28
29 1000 void PhotonGBTFilterValidator::Run(hipo::banklist& banks) const
30 {
31 // get the particle bank
32
2/4
✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1000 times.
✗ Branch 3 not taken.
2000 auto& particle_bank = GetBank(banks, b_particle, "REC::Particle");
33
34 std::vector<ROOT::Math::PxPyPzEVector> photons;
35
3/4
✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7143 times.
✓ Branch 3 taken 1000 times.
8143 for(auto const& row : particle_bank.getRowList()) {
36 7143 auto pid = particle_bank.getInt("pid",row);
37
2/2
✓ Branch 0 taken 5278 times.
✓ Branch 1 taken 1865 times.
7143 if(pid!=22) continue;
38 1865 float px = particle_bank.getFloat("px",row);
39 1865 float py = particle_bank.getFloat("py",row);
40 1865 float pz = particle_bank.getFloat("pz",row);
41 float E = std::hypot(px,py,pz);
42
1/2
✓ Branch 0 taken 1865 times.
✗ Branch 1 not taken.
1865 ROOT::Math::PxPyPzEVector phot(px,py,pz,E);
43
5/10
✓ Branch 0 taken 1865 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1865 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1865 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1530 times.
✓ Branch 7 taken 335 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
5595 if(m_algo_seq->Get<PhotonGBTFilter>("clas12::PhotonGBTFilter")->ForwardDetectorFilter(phot.Theta()))
44
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 photons.push_back(phot);
45 }
46
47 // run the photon filter
48
1/2
✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
1000 m_algo_seq->Run(banks);
49
50 std::vector<ROOT::Math::PxPyPzEVector> filtered_photons;
51
3/4
✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1103 times.
✓ Branch 3 taken 1000 times.
2103 for(auto const& row : particle_bank.getRowList()) {
52 1103 auto pid = particle_bank.getInt("pid",row);
53
2/2
✓ Branch 0 taken 651 times.
✓ Branch 1 taken 452 times.
1103 if(pid!=22) continue;
54 452 float px = particle_bank.getFloat("px",row);
55 452 float py = particle_bank.getFloat("py",row);
56 452 float pz = particle_bank.getFloat("pz",row);
57 float E = std::hypot(px,py,pz);
58
1/2
✓ Branch 0 taken 452 times.
✗ Branch 1 not taken.
452 ROOT::Math::PxPyPzEVector phot(px,py,pz,E);
59
1/2
✓ Branch 0 taken 452 times.
✗ Branch 1 not taken.
452 filtered_photons.push_back(phot);
60 }
61
62 // fill the plots
63
1/2
✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
1000 FillHistograms(photons, 0);
64
1/2
✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
1000 FillHistograms(filtered_photons, 1);
65
66 1000 }
67
68
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 void PhotonGBTFilterValidator::InitializeHistograms() {
69 std::vector<std::pair<int, TString>> histInfos = {
70 {0, "before"},
71 {1, "after"}
72
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3 };
73
74
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (const auto& [idx, label] : histInfos) {
75
4/10
✓ 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 not taken.
2 h_Mgg[idx] = new TH1F(Form("h_Mgg_%s", label.Data()), ";M_{#gamma#gamma} [GeV]", 100, 0.02, 0.5);
76
4/10
✓ 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 not taken.
2 h_P[idx] = new TH1F(Form("h_P_%s", label.Data()), ";P(#gamma) [GeV]", 100, 0, 2);
77
4/10
✓ 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 not taken.
2 h_Th[idx] = new TH1F(Form("h_Th_%s", label.Data()), ";#theta(#gamma) [deg]", 100, 0, 36);
78
3/8
✓ 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 not taken.
✗ Branch 7 not taken.
2 h_Phi[idx] = new TH1F(Form("h_Phi_%s", label.Data()), ";#phi(#gamma) [deg]", 100, -180, 180);
79
80
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 int color = (idx == 0) ? kBlack : kRed;
81
82
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 ConfigureHistogram(h_Mgg[idx], color);
83
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 ConfigureHistogram(h_P[idx], color);
84
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 ConfigureHistogram(h_Th[idx], color);
85
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 ConfigureHistogram(h_Phi[idx], color);
86 }
87
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1 }
88
89 8 void PhotonGBTFilterValidator::ConfigureHistogram(TH1F* hist, int color) {
90 8 hist->SetLineColor(color);
91 8 hist->SetLineWidth(2);
92 8 hist->GetXaxis()->SetTitleSize(0.06);
93 8 hist->GetYaxis()->SetTitleSize(0.06);
94 8 }
95
96 2000 void PhotonGBTFilterValidator::FillHistograms(const std::vector<ROOT::Math::PxPyPzEVector>& photons, int idx) const
97 {
98
2/2
✓ Branch 0 taken 1982 times.
✓ Branch 1 taken 2000 times.
3982 for (const auto& photon : photons) {
99 1982 h_P.at(idx)->Fill(photon.P());
100 1982 h_Th.at(idx)->Fill(photon.Theta() * 180.0 / M_PI);
101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1982 times.
3964 h_Phi.at(idx)->Fill(photon.Phi() * 180.0 / M_PI);
102 }
103
104
2/2
✓ Branch 0 taken 1982 times.
✓ Branch 1 taken 2000 times.
3982 for (size_t i = 0; i < photons.size(); ++i) {
105
2/2
✓ Branch 0 taken 2014 times.
✓ Branch 1 taken 1982 times.
3996 for (size_t j = i + 1; j < photons.size(); ++j) {
106 2014 auto diphoton = photons[i] + photons[j];
107 2014 h_Mgg.at(idx)->Fill(diphoton.M());
108 }
109 }
110 2000 }
111
112 1 void PhotonGBTFilterValidator::Stop()
113 {
114
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
2 if(GetOutputDirectory()){
115 int n_rows = 2;
116 int n_cols = 2;
117
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 auto canv = new TCanvas("c","c",n_cols*800,n_rows*800);
118 1 canv->Divide(n_cols,n_rows);
119 1 gStyle->SetOptStat(0);
120
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for(int pad_num = 0; pad_num < 4; pad_num++){
121 4 auto pad = canv->GetPad(pad_num+1);
122 4 pad->cd();
123 4 pad->SetGrid(1, 1);
124 4 pad->SetLogz();
125 4 pad->SetLeftMargin(0.12);
126 4 pad->SetRightMargin(0.12);
127 4 pad->SetBottomMargin(0.12);
128
4/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
4 switch(pad_num){
129 1 case 0:
130 1 h_Mgg[0]->Draw("hist");
131 1 h_Mgg[1]->Draw("hist same");
132 1 break;
133 1 case 1:
134 1 h_P[0]->Draw("hist");
135 1 h_P[1]->Draw("hist same");
136 1 break;
137 1 case 2:
138 1 h_Th[0]->Draw("hist");
139 1 h_Th[1]->Draw("hist same");
140 1 break;
141 1 case 3:
142 1 h_Phi[0]->Draw("hist");
143 1 h_Phi[1]->Draw("hist same");
144 1 break;
145 }
146 }
147
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
2 canv->SaveAs(m_output_file_basename + "_plot.png");
148 1 m_output_file->Write();
149 1 m_log->Info("Wrote output file {}", m_output_file->GetName());
150 1 m_output_file->Close();
151 }
152 1 }
153
154 }
155