GCC Code Coverage Report


Directory: ./
File: src/iguana/algorithms/clas12/FiducialFilter/Validator.cc
Date: 2025-01-05 09:03:17
Exec Total Coverage
Lines: 121 122 99.2%
Functions: 3 3 100.0%
Branches: 137 244 56.1%

Line Branch Exec Source
1 #include "Validator.h"
2 #include "Algorithm.h"
3
4 #include <TProfile.h>
5 #include <TStyle.h>
6
7 namespace iguana::clas12 {
8
9 REGISTER_IGUANA_VALIDATOR(FiducialFilterValidator);
10
11 1 void FiducialFilterValidator::Start(hipo::banklist& banks)
12 {
13 // define the algorithm sequence
14 2 m_algo_seq = std::make_unique<AlgorithmSequence>();
15
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");
16
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::FiducialFilter");
17
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);
18 1 m_algo_seq->Start(banks);
19
20 // get bank indices
21
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 b_particle = GetBankIndex(banks, "REC::Particle");
22
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 b_traj = GetBankIndex(banks, "REC::Traj");
23
24 // set an output file
25 1 auto output_dir = GetOutputDirectory();
26
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(output_dir) {
27
3/6
✓ 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.
2 m_output_file_basename = output_dir.value() + "/fiducial";
28
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");
29 }
30
31 // define plots
32
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 gStyle->SetOptStat(0);
33
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for(auto const& pdg : u_pdg_list) {
34
2/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
4 TString particle_name = particle::name.at(particle::PDG(pdg));
35
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 TString particle_title = particle::title.at(particle::PDG(pdg));
36
37 TH2D *DC1_before = new TH2D(
38
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
8 "DC1_before_"+particle_name,
39
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 particle_title + " DC1 w/o fiducial cuts; x [cm]; y [cm]",
40 4 100, DC1xleft, DC1xright,
41
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 100, DC1ybottom, DC1ytop
42
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 );
43 TH2D *DC1_after = new TH2D(
44
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
8 "DC1_after_"+particle_name,
45
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 particle_title + " DC1 w fiducial cuts; x [cm]; y [cm]",
46 4 100, DC1xleft, DC1xright,
47
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 100, DC1ybottom, DC1ytop
48
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 );
49
50 TH2D *DC2_before = new TH2D(
51
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
8 "DC2_before_" + particle_name,
52
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 particle_title + " DC2 w/o fiducial cuts; x [cm]; y [cm]",
53 4 100, DC2xleft, DC2xright,
54
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 100, DC2ybottom, DC2ytop
55
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 );
56 TH2D *DC2_after = new TH2D(
57
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
8 "DC2_after_" + particle_name,
58
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 particle_title + " DC2 w fiducial cuts; x [cm]; y [cm]",
59 4 100, DC2xleft, DC2xright,
60
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 100, DC2ybottom, DC2ytop
61
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 );
62
63 TH2D *DC3_before = new TH2D(
64
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
8 "DC3_before_" + particle_name,
65
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 particle_title + " DC3 w/o fiducial cuts; x [cm]; y [cm]",
66 4 100, DC3xleft, DC3xright,
67
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 100, DC3ybottom, DC3ytop
68
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 );
69 TH2D *DC3_after = new TH2D(
70
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
8 "DC3_after_" + particle_name,
71
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 particle_title + " DC3 w fiducial cuts; x [cm]; y [cm]",
72 4 100, DC3xleft, DC3xright,
73
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 100, DC3ybottom, DC3ytop
74
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 );
75
76
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 u_DC1_before.insert({pdg, DC1_before});
77
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 u_DC1_after.insert({pdg, DC1_after});
78
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 u_DC2_before.insert({pdg, DC2_before});
79
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 u_DC2_after.insert({pdg, DC2_after});
80
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 u_DC3_before.insert({pdg, DC3_before});
81 4 u_DC3_after.insert({pdg, DC3_after});
82 4 }
83 1 }
84
85
86 1000 void FiducialFilterValidator::Run(hipo::banklist& banks) const
87 {
88 // get the momenta before
89
1/2
✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
1000 auto& particle_bank = GetBank(banks, b_particle, "REC::Particle");
90
1/2
✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
1000 auto& trajBank = GetBank(banks, b_traj, "REC::Traj");
91 // get a pindex'd map of the REC::Traj data
92 1000 auto traj_map = FiducialFilter::GetTrajMap(trajBank);
93
94
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()){
95 7143 auto pid = particle_bank.getInt("pid", row);
96
6/6
✓ Branch 0 taken 5513 times.
✓ Branch 1 taken 1630 times.
✓ Branch 2 taken 5052 times.
✓ Branch 3 taken 461 times.
✓ Branch 4 taken 4795 times.
✓ Branch 5 taken 257 times.
7672 if(pid!=11&&pid!=211&&pid!=-211&&pid!=2212) continue;
97
2/2
✓ Branch 0 taken 529 times.
✓ Branch 1 taken 1819 times.
2348 if (traj_map.find(row) == traj_map.end()) {
98 529 continue;
99 }
100
2/4
✓ Branch 0 taken 1819 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1819 times.
✗ Branch 3 not taken.
1819 auto traj_row = traj_map.at(row);
101
1/2
✓ Branch 0 taken 1819 times.
✗ Branch 1 not taken.
1819 u_DC1_before.at(pid)->Fill(traj_row.x1,traj_row.y1);
102
1/2
✓ Branch 0 taken 1819 times.
✗ Branch 1 not taken.
1819 u_DC2_before.at(pid)->Fill(traj_row.x2,traj_row.y2);
103
1/2
✓ Branch 0 taken 1819 times.
✗ Branch 1 not taken.
1819 u_DC3_before.at(pid)->Fill(traj_row.x3,traj_row.y3);
104 }
105
106 // run the fiducial cuts
107
1/2
✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
1000 m_algo_seq->Run(banks);
108
109 // fill the plots
110
3/4
✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1442 times.
✓ Branch 3 taken 1000 times.
2442 for(auto const& row : particle_bank.getRowList()) {
111
112 1442 auto pid = particle_bank.getInt("pid", row);
113
5/6
✓ Branch 0 taken 485 times.
✓ Branch 1 taken 957 times.
✓ Branch 2 taken 150 times.
✓ Branch 3 taken 335 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 150 times.
1442 if(pid!=11&&pid!=211&&pid!=-211&&pid!=2212) continue;
114
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1442 times.
1442 if (traj_map.find(row) == traj_map.end()) {
115 continue;
116 }
117
2/4
✓ Branch 0 taken 1442 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1442 times.
✗ Branch 3 not taken.
1442 auto traj_row = traj_map.at(row);
118
1/2
✓ Branch 0 taken 1442 times.
✗ Branch 1 not taken.
1442 u_DC1_after.at(pid)->Fill(traj_row.x1,traj_row.y1);
119
1/2
✓ Branch 0 taken 1442 times.
✗ Branch 1 not taken.
1442 u_DC2_after.at(pid)->Fill(traj_row.x2,traj_row.y2);
120
1/2
✓ Branch 0 taken 1442 times.
✗ Branch 1 not taken.
1442 u_DC3_after.at(pid)->Fill(traj_row.x3,traj_row.y3);
121 }
122 1000 }
123
124
125 1 void FiducialFilterValidator::Stop()
126 {
127
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
2 if(GetOutputDirectory()) {
128 int n_cols = 2;
129 int n_rows = 2;
130
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for(int r=0;r<3;r++){
131 3 TString canv_name = Form("beforecanv%d", r);
132
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 auto canv = new TCanvas(canv_name, canv_name, n_cols * 800, n_rows * 600);
133
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 canv->Divide(n_cols, n_rows);
134 int pad_num = 0;
135
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 3 times.
15 for(auto const& pdg : u_pdg_list){
136
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 auto pad = canv->GetPad(++pad_num);
137
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 pad->cd();
138
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 pad->SetGrid(1, 1);
139
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 pad->SetLogz();
140
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 pad->SetLeftMargin(0.12);
141
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 pad->SetRightMargin(0.12);
142
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 pad->SetBottomMargin(0.12);
143
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
12 if(r==0){
144
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 u_DC1_before.at(pdg)->Draw("colz");
145
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 }else if(r==1){
146
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 u_DC2_before.at(pdg)->Draw("colz");
147 }else{
148
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 u_DC3_before.at(pdg)->Draw("colz");
149 }
150 }
151
5/10
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
6 canv->SaveAs(m_output_file_basename + "_before_DC" + std::to_string(r+1) + ".png");
152 3 }
153
154
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for(int r=0;r<3;r++){
155 3 TString canv_name = Form("aftercanv%d", r);
156
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 auto canv = new TCanvas(canv_name, canv_name, n_cols * 800, n_rows * 600);
157
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 canv->Divide(n_cols, n_rows);
158 int pad_num = 0;
159
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 3 times.
15 for(auto const& pdg : u_pdg_list){
160
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 auto pad = canv->GetPad(++pad_num);
161
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 pad->cd();
162
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 pad->SetGrid(1, 1);
163
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 pad->SetLogz();
164
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 pad->SetLeftMargin(0.12);
165
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 pad->SetRightMargin(0.12);
166
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 pad->SetBottomMargin(0.12);
167
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
12 if(r==0){
168
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 u_DC1_after.at(pdg)->Draw("colz");
169
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 }else if(r==1){
170
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 u_DC2_after.at(pdg)->Draw("colz");
171 }else{
172
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 u_DC3_after.at(pdg)->Draw("colz");
173 }
174 }
175
5/10
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
6 canv->SaveAs(m_output_file_basename + "_after_DC" + std::to_string(r+1) + ".png");
176 3 }
177 1 m_output_file->Write();
178 1 m_log->Info("Wrote output file {}", m_output_file->GetName());
179 1 m_output_file->Close();
180 }
181 1 }
182 }
183