GCC Code Coverage Report


Directory: ./
File: src/iguana/algorithms/clas12/SectorFinder/Validator.cc
Date: 2025-03-24 18:50:00
Exec Total Coverage
Lines: 83 83 100.0%
Functions: 3 3 100.0%
Branches: 93 172 54.1%

Line Branch Exec Source
1 #include "Validator.h"
2
3 #include <TProfile.h>
4 #include <TStyle.h>
5
6 namespace iguana::clas12 {
7
8 REGISTER_IGUANA_VALIDATOR(SectorFinderValidator);
9
10 1 void SectorFinderValidator::Start(hipo::banklist& banks)
11 {
12 // define the algorithm sequence
13 2 m_algo_seq = std::make_unique<AlgorithmSequence>();
14
2/4
✓ Branch 0 (7→8) taken 1 times.
✗ Branch 1 (7→116) not taken.
✓ Branch 2 (8→9) taken 1 times.
✗ Branch 3 (8→114) not taken.
2 m_algo_seq->Add("clas12::EventBuilderFilter");
15
2/4
✓ Branch 0 (12→13) taken 1 times.
✗ Branch 1 (12→120) not taken.
✓ Branch 2 (13→14) taken 1 times.
✗ Branch 3 (13→118) not taken.
2 m_algo_seq->Add("clas12::SectorFinder");
16
4/10
✓ Branch 0 (17→18) taken 1 times.
✗ Branch 1 (17→126) not taken.
✓ Branch 2 (18→19) taken 1 times.
✗ Branch 3 (18→124) not taken.
✓ Branch 4 (19→20) taken 1 times.
✗ Branch 5 (19→122) not taken.
✓ Branch 6 (22→23) taken 1 times.
✗ Branch 7 (22→25) not taken.
✗ Branch 8 (126→127) not taken.
✗ Branch 9 (126→129) not taken.
3 m_algo_seq->SetOption<std::vector<int>>("clas12::EventBuilderFilter", "pids", u_pdg_list);
17
3/6
✓ Branch 0 (26→27) taken 1 times.
✗ Branch 1 (26→134) not taken.
✓ Branch 2 (27→28) taken 1 times.
✗ Branch 3 (27→132) not taken.
✓ Branch 4 (28→29) taken 1 times.
✗ Branch 5 (28→130) not taken.
2 m_algo_seq->SetOption<std::string>("clas12::SectorFinder", "bank_charged", "REC::Track");
18
3/6
✓ Branch 0 (33→34) taken 1 times.
✗ Branch 1 (33→140) not taken.
✓ Branch 2 (34→35) taken 1 times.
✗ Branch 3 (34→138) not taken.
✓ Branch 4 (35→36) taken 1 times.
✗ Branch 5 (35→136) not taken.
2 m_algo_seq->SetOption<std::string>("clas12::SectorFinder", "bank_uncharged", "default");
19 1 m_algo_seq->Start(banks);
20
21
22
1/2
✓ Branch 0 (41→42) taken 1 times.
✗ Branch 1 (41→142) not taken.
1 b_particle = GetBankIndex(banks, "REC::Particle");
23
1/2
✓ Branch 0 (44→45) taken 1 times.
✗ Branch 1 (44→144) not taken.
1 b_cal = GetBankIndex(banks, "REC::Calorimeter");
24
1/2
✓ Branch 0 (47→48) taken 1 times.
✗ Branch 1 (47→146) not taken.
1 b_sector = GetBankIndex(banks, "REC::Particle::Sector");
25
26 // set an output file
27 1 auto output_dir = GetOutputDirectory();
28
1/2
✓ Branch 0 (50→51) taken 1 times.
✗ Branch 1 (50→61) not taken.
1 if(output_dir) {
29
3/8
✓ Branch 0 (51→52) taken 1 times.
✗ Branch 1 (51→187) not taken.
✓ Branch 2 (52→53) taken 1 times.
✗ Branch 3 (52→148) not taken.
✓ Branch 4 (54→55) taken 1 times.
✗ Branch 5 (54→187) not taken.
✗ Branch 6 (187→188) not taken.
✗ Branch 7 (187→190) not taken.
2 m_output_file_basename = output_dir.value() + "/sector_finder";
30
2/4
✓ Branch 0 (55→56) taken 1 times.
✗ Branch 1 (55→152) not taken.
✓ Branch 2 (58→59) taken 1 times.
✗ Branch 3 (58→150) not taken.
2 m_output_file = new TFile(m_output_file_basename + ".root", "RECREATE");
31 }
32
33 // define plots
34
1/2
✓ Branch 0 (61→62) taken 1 times.
✗ Branch 1 (61→187) not taken.
1 gStyle->SetOptStat(0);
35
2/2
✓ Branch 0 (107→63) taken 2 times.
✓ Branch 1 (107→108) taken 1 times.
3 for(auto const& pdg : u_pdg_list) {
36 std::vector<TH2D*> YvsX;
37
2/6
✓ Branch 0 (63→64) taken 2 times.
✗ Branch 1 (63→181) not taken.
✓ Branch 2 (64→65) taken 2 times.
✗ Branch 3 (64→181) not taken.
✗ Branch 4 (181→182) not taken.
✗ Branch 5 (181→184) not taken.
2 TString particle_name = particle::name.at(particle::PDG(pdg));
38
2/4
✓ Branch 0 (65→66) taken 2 times.
✗ Branch 1 (65→179) not taken.
✓ Branch 2 (66→67) taken 2 times.
✗ Branch 3 (66→179) not taken.
2 TString particle_title = particle::title.at(particle::PDG(pdg));
39
2/2
✓ Branch 0 (94→68) taken 12 times.
✓ Branch 1 (94→95) taken 2 times.
14 for(int sec = 1; sec <= 6; sec++) {
40
2/4
✓ Branch 0 (68→69) taken 12 times.
✗ Branch 1 (68→177) not taken.
✓ Branch 2 (69→70) taken 12 times.
✗ Branch 3 (69→177) not taken.
12 TString sector_name = Form("sec%d", sec);
41
2/4
✓ Branch 0 (70→71) taken 12 times.
✗ Branch 1 (70→171) not taken.
✓ Branch 2 (71→72) taken 12 times.
✗ Branch 3 (71→171) not taken.
12 TString sector_title = Form("sector %d", sec);
42
1/2
✓ Branch 0 (84→85) taken 12 times.
✗ Branch 1 (84→154) not taken.
12 YvsX.push_back(new TH2D(
43
3/6
✓ Branch 0 (78→79) taken 12 times.
✗ Branch 1 (78→160) not taken.
✓ Branch 2 (79→80) taken 12 times.
✗ Branch 3 (79→158) not taken.
✓ Branch 4 (80→81) taken 12 times.
✗ Branch 5 (80→156) not taken.
24 "YvsX_" + particle_name + "_" + sector_name,
44
3/8
✓ Branch 0 (73→74) taken 12 times.
✗ Branch 1 (73→166) not taken.
✓ Branch 2 (74→75) taken 12 times.
✗ Branch 3 (74→164) not taken.
✓ Branch 4 (75→76) taken 12 times.
✗ Branch 5 (75→162) not taken.
✗ Branch 6 (166→167) not taken.
✗ Branch 7 (166→168) not taken.
24 particle_title + " Calorimeter Hit Position, " + sector_title + ";X [cm];Y [cm]",
45 50, -500, 500,
46
1/2
✓ Branch 0 (83→84) taken 12 times.
✗ Branch 1 (83→154) not taken.
12 50, -500, 500));
47 12 }
48 2 u_YvsX.insert({pdg, YvsX});
49 2 }
50
1/2
✓ Branch 0 (110→111) taken 1 times.
✗ Branch 1 (110→113) not taken.
1 u_IsInFD = new TH1D(
51 "IsInFD",
52 "e^{-} with #theta>6.5^{o} Sector; e^{-} Sector",
53
1/2
✓ Branch 0 (109→110) taken 1 times.
✗ Branch 1 (109→185) not taken.
1 7, -0.5, 6.5);
54
55 1 }
56
57 1000 void SectorFinderValidator::Run(hipo::banklist& banks) const
58 {
59
60
1/2
✓ Branch 0 (3→4) taken 1000 times.
✗ Branch 1 (3→46) not taken.
1000 auto& particle_bank = GetBank(banks, b_particle, "REC::Particle");
61
2/4
✓ Branch 0 (5→6) taken 1000 times.
✗ Branch 1 (5→50) not taken.
✓ Branch 2 (6→7) taken 1000 times.
✗ Branch 3 (6→48) not taken.
1000 auto& sector_bank = GetBank(banks, b_sector, "REC::Particle::Sector");
62
2/4
✓ Branch 0 (8→9) taken 1000 times.
✗ Branch 1 (8→53) not taken.
✓ Branch 2 (9→10) taken 1000 times.
✗ Branch 3 (9→51) not taken.
2000 auto& cal_bank = GetBank(banks, b_cal, "REC::Calorimeter");
63
64
65 1000 m_algo_seq->Run(banks);
66
67 // lock the mutex, so we can mutate plots
68 1000 std::scoped_lock<std::mutex> lock(m_mutex);
69 // fill the plots
70
3/4
✓ Branch 0 (13→14) taken 1000 times.
✗ Branch 1 (13→54) not taken.
✓ Branch 2 (43→15) taken 2516 times.
✓ Branch 3 (43→44) taken 1000 times.
3516 for(auto const& row : particle_bank.getRowList()) {
71
72 2516 auto pdg = particle_bank.getInt("pid", row);
73 2516 auto sector = sector_bank.getInt("sector", row);
74
75 double x=0,y=0;
76
3/4
✓ Branch 0 (17→18) taken 2516 times.
✗ Branch 1 (17→54) not taken.
✓ Branch 2 (25→19) taken 18708 times.
✓ Branch 3 (25→26) taken 2516 times.
21224 for(auto const& rowcal : cal_bank.getRowList()){
77
2/2
✓ Branch 0 (20→21) taken 2533 times.
✓ Branch 1 (20→24) taken 16175 times.
18708 if(cal_bank.getShort("pindex", rowcal)==row){
78 2533 x=cal_bank.getFloat("x", rowcal);
79 2533 y=cal_bank.getFloat("y", rowcal);
80 }
81 }
82
83
2/2
✓ Branch 0 (26→27) taken 651 times.
✓ Branch 1 (26→35) taken 1865 times.
2516 if(pdg==11){
84 651 double Px=particle_bank.getFloat("px", row);
85 651 double Py=particle_bank.getFloat("py", row);
86 651 double Pz=particle_bank.getFloat("pz", row);
87 651 double P=sqrt(Px*Px+Py*Py+Pz*Pz);
88 651 double Theta=acos(Pz/P) * 180./M_PI ;
89 //electrons are in FT or FD
90 //sector should always be 1 if theta is larger than 5.5 degrees
91
2/2
✓ Branch 0 (30→31) taken 125 times.
✓ Branch 1 (30→35) taken 526 times.
651 if (Theta>6.5){
92
1/2
✓ Branch 0 (31→32) taken 125 times.
✗ Branch 1 (31→54) not taken.
125 u_IsInFD->Fill(sector);
93
2/2
✓ Branch 0 (32→33) taken 3 times.
✓ Branch 1 (32→37) taken 122 times.
125 if(sector==0){
94 3 m_log->Trace("e' with theta={} and sector==0, this should not happen", Theta);
95 }
96 }
97 }
98
99 // skip central particle, or unknown sector
100
2/2
✓ Branch 0 (35→36) taken 851 times.
✓ Branch 1 (35→37) taken 1543 times.
2394 if(sector == 0)
101 851 continue;
102
2/4
✓ Branch 0 (37→38) taken 1665 times.
✗ Branch 1 (37→54) not taken.
✓ Branch 2 (38→39) taken 1665 times.
✗ Branch 3 (38→54) not taken.
1665 m_log->Trace("Filling SectorFinder Validator, pdg {} sector {} pindex {}", pdg, sector, row);
103
2/4
✓ Branch 0 (39→40) taken 1665 times.
✗ Branch 1 (39→54) not taken.
✓ Branch 2 (40→41) taken 1665 times.
✗ Branch 3 (40→54) not taken.
1665 u_YvsX.at(pdg).at(sector - 1)->Fill(x, y);
104 }
105
106 1000 }
107
108
109 1 void SectorFinderValidator::Stop()
110 {
111
1/2
✓ Branch 0 (6→7) taken 1 times.
✗ Branch 1 (6→53) not taken.
2 if(GetOutputDirectory()) {
112
2/2
✓ Branch 0 (40→8) taken 2 times.
✓ Branch 1 (40→41) taken 1 times.
3 for(auto const& [pdg, plots] : u_YvsX) {
113 int n_cols = 3;
114 int n_rows = 2;
115 2 TString canv_name = Form("canv%d", pdg);
116
1/2
✓ Branch 0 (13→14) taken 2 times.
✗ Branch 1 (13→54) not taken.
2 auto canv = new TCanvas(canv_name, canv_name, n_cols * 800, n_rows * 600);
117
1/2
✓ Branch 0 (14→15) taken 2 times.
✗ Branch 1 (14→66) not taken.
2 canv->Divide(n_cols, n_rows);
118 int pad_num = 0;
119
2/2
✓ Branch 0 (24→16) taken 12 times.
✓ Branch 1 (24→25) taken 2 times.
14 for(auto const& plot : plots) {
120
1/2
✓ Branch 0 (16→17) taken 12 times.
✗ Branch 1 (16→66) not taken.
12 auto pad = canv->GetPad(++pad_num);
121
1/2
✓ Branch 0 (17→18) taken 12 times.
✗ Branch 1 (17→66) not taken.
12 pad->cd();
122
1/2
✓ Branch 0 (18→19) taken 12 times.
✗ Branch 1 (18→66) not taken.
12 pad->SetGrid(1, 1);
123
1/2
✓ Branch 0 (19→20) taken 12 times.
✗ Branch 1 (19→66) not taken.
12 pad->SetLeftMargin(0.12);
124
1/2
✓ Branch 0 (20→21) taken 12 times.
✗ Branch 1 (20→66) not taken.
12 pad->SetRightMargin(0.12);
125
1/2
✓ Branch 0 (21→22) taken 12 times.
✗ Branch 1 (21→66) not taken.
12 pad->SetBottomMargin(0.12);
126
1/2
✓ Branch 0 (22→23) taken 12 times.
✗ Branch 1 (22→66) not taken.
12 plot->Draw("colz");
127 }
128
5/10
✓ Branch 0 (26→27) taken 2 times.
✗ Branch 1 (26→64) not taken.
✓ Branch 2 (27→28) taken 2 times.
✗ Branch 3 (27→62) not taken.
✓ Branch 4 (28→29) taken 2 times.
✗ Branch 5 (28→60) not taken.
✓ Branch 6 (29→30) taken 2 times.
✗ Branch 7 (29→58) not taken.
✓ Branch 8 (32→33) taken 2 times.
✗ Branch 9 (32→56) not taken.
4 canv->SaveAs(m_output_file_basename + "_" + std::to_string(pdg) + ".png");
129
130 2 }
131
132
1/2
✓ Branch 0 (42→43) taken 1 times.
✗ Branch 1 (42→68) not taken.
1 auto canv1D = new TCanvas("1D canvas","1D canvas",800, 600);
133 1 u_IsInFD->Draw();
134
1/2
✓ Branch 0 (47→48) taken 1 times.
✗ Branch 1 (47→70) not taken.
2 canv1D->SaveAs(m_output_file_basename+"_elIsInFD.png");
135
136 1 m_output_file->Write();
137 1 m_log->Info("Wrote output file {}", m_output_file->GetName());
138 1 m_output_file->Close();
139 }
140 1 }
141
142 }
143