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 (7→8) taken 1 times.
✗ Branch 1 (7→48) not taken.
✓ Branch 2 (8→9) taken 1 times.
✗ Branch 3 (8→46) not taken.
|
2 | m_algo_seq->Add("clas12::PhotonGBTFilter"); |
12 |
2/4✓ Branch 0 (12→13) taken 1 times.
✗ Branch 1 (12→52) not taken.
✓ Branch 2 (13→14) taken 1 times.
✗ Branch 3 (13→50) not taken.
|
2 | m_algo_seq->Add("clas12::EventBuilderFilter"); |
13 |
4/10✓ Branch 0 (17→18) taken 1 times.
✗ Branch 1 (17→58) not taken.
✓ Branch 2 (18→19) taken 1 times.
✗ Branch 3 (18→56) not taken.
✓ Branch 4 (19→20) taken 1 times.
✗ Branch 5 (19→54) not taken.
✓ Branch 6 (22→23) taken 1 times.
✗ Branch 7 (22→25) not taken.
✗ Branch 8 (58→59) not taken.
✗ Branch 9 (58→61) 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 (27→28) taken 1 times.
✗ Branch 1 (27→62) 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 (30→31) taken 1 times.
✗ Branch 1 (30→41) not taken.
|
1 | if(output_dir) { |
22 |
3/8✓ Branch 0 (31→32) taken 1 times.
✗ Branch 1 (31→70) not taken.
✓ Branch 2 (32→33) taken 1 times.
✗ Branch 3 (32→64) not taken.
✓ Branch 4 (34→35) taken 1 times.
✗ Branch 5 (34→70) not taken.
✗ Branch 6 (70→71) not taken.
✗ Branch 7 (70→73) not taken.
|
2 | m_output_file_basename = output_dir.value() + "/photon_gbt"; |
23 |
2/4✓ Branch 0 (35→36) taken 1 times.
✗ Branch 1 (35→68) not taken.
✓ Branch 2 (38→39) taken 1 times.
✗ Branch 3 (38→66) not taken.
|
2 | m_output_file = new TFile(m_output_file_basename + ".root", "RECREATE"); |
24 | } | ||
25 | |||
26 |
1/2✓ Branch 0 (41→42) taken 1 times.
✗ Branch 1 (41→70) 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 (3→4) taken 1000 times.
✗ Branch 1 (3→47) not taken.
✓ Branch 2 (5→6) taken 1000 times.
✗ Branch 3 (5→55) 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 (5→6) taken 1000 times.
✗ Branch 1 (5→55) not taken.
✓ Branch 2 (23→7) taken 7143 times.
✓ Branch 3 (23→24) 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 (8→9) taken 5278 times.
✓ Branch 1 (8→10) 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 (14→15) taken 1865 times.
✗ Branch 1 (14→55) not taken.
|
1865 | ROOT::Math::PxPyPzEVector phot(px,py,pz,E); |
43 |
5/10✓ Branch 0 (14→15) taken 1865 times.
✗ Branch 1 (14→55) not taken.
✓ Branch 2 (15→16) taken 1865 times.
✗ Branch 3 (15→49) not taken.
✓ Branch 4 (17→18) taken 1865 times.
✗ Branch 5 (17→49) not taken.
✓ Branch 6 (19→20) taken 1530 times.
✓ Branch 7 (19→21) taken 335 times.
✗ Branch 8 (55→56) not taken.
✗ Branch 9 (55→58) not taken.
|
5595 | if(m_algo_seq->Get<PhotonGBTFilter>("clas12::PhotonGBTFilter")->ForwardDetectorFilter(phot.Theta())) |
44 |
1/2✓ Branch 0 (20→21) taken 1530 times.
✗ Branch 1 (20→55) not taken.
|
1530 | photons.push_back(phot); |
45 | } | ||
46 | |||
47 | // run the photon filter | ||
48 |
1/2✓ Branch 0 (24→25) taken 1000 times.
✗ Branch 1 (24→55) not taken.
|
1000 | m_algo_seq->Run(banks); |
49 | |||
50 | std::vector<ROOT::Math::PxPyPzEVector> filtered_photons; | ||
51 |
3/4✓ Branch 0 (25→26) taken 1000 times.
✗ Branch 1 (25→51) not taken.
✓ Branch 2 (37→27) taken 1103 times.
✓ Branch 3 (37→38) 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 (28→29) taken 651 times.
✓ Branch 1 (28→30) 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 (34→35) taken 452 times.
✗ Branch 1 (34→51) not taken.
|
452 | ROOT::Math::PxPyPzEVector phot(px,py,pz,E); |
59 |
1/2✓ Branch 0 (34→35) taken 452 times.
✗ Branch 1 (34→51) not taken.
|
452 | filtered_photons.push_back(phot); |
60 | } | ||
61 | |||
62 | // fill the plots | ||
63 |
1/2✓ Branch 0 (38→39) taken 1000 times.
✗ Branch 1 (38→51) not taken.
|
1000 | FillHistograms(photons, 0); |
64 |
1/2✓ Branch 0 (39→40) taken 1000 times.
✗ Branch 1 (39→51) not taken.
|
1000 | FillHistograms(filtered_photons, 1); |
65 | |||
66 | 1000 | } | |
67 | |||
68 |
1/2✓ Branch 0 (2→3) taken 1 times.
✗ Branch 1 (2→59) 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 (6→7) not taken.
✓ Branch 1 (6→8) taken 1 times.
✓ Branch 2 (9→10) taken 2 times.
✓ Branch 3 (9→12) taken 1 times.
✗ Branch 4 (55→56) not taken.
✗ Branch 5 (55→58) not taken.
|
3 | }; |
73 | |||
74 |
2/2✓ Branch 0 (52→13) taken 2 times.
✓ Branch 1 (52→53) taken 1 times.
|
3 | for (const auto& [idx, label] : histInfos) { |
75 |
4/10✓ Branch 0 (17→18) taken 2 times.
✗ Branch 1 (17→64) not taken.
✓ Branch 2 (18→19) taken 2 times.
✗ Branch 3 (18→64) not taken.
✓ Branch 4 (19→20) taken 2 times.
✗ Branch 5 (19→64) not taken.
✓ Branch 6 (20→21) taken 2 times.
✗ Branch 7 (20→76) not taken.
✗ Branch 8 (64→65) not taken.
✗ Branch 9 (64→66) 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 (24→25) taken 2 times.
✗ Branch 1 (24→67) not taken.
✓ Branch 2 (25→26) taken 2 times.
✗ Branch 3 (25→67) not taken.
✓ Branch 4 (26→27) taken 2 times.
✗ Branch 5 (26→67) not taken.
✓ Branch 6 (27→28) taken 2 times.
✗ Branch 7 (27→76) not taken.
✗ Branch 8 (67→68) not taken.
✗ Branch 9 (67→69) 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 (31→32) taken 2 times.
✗ Branch 1 (31→70) not taken.
✓ Branch 2 (32→33) taken 2 times.
✗ Branch 3 (32→70) not taken.
✓ Branch 4 (33→34) taken 2 times.
✗ Branch 5 (33→70) not taken.
✓ Branch 6 (34→35) taken 2 times.
✗ Branch 7 (34→76) not taken.
✗ Branch 8 (70→71) not taken.
✗ Branch 9 (70→72) 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 (38→39) taken 2 times.
✗ Branch 1 (38→73) not taken.
✓ Branch 2 (39→40) taken 2 times.
✗ Branch 3 (39→73) not taken.
✓ Branch 4 (40→41) taken 2 times.
✗ Branch 5 (40→73) not taken.
✗ Branch 6 (73→74) not taken.
✗ Branch 7 (73→75) 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 (41→42) taken 1 times.
✓ Branch 1 (41→43) taken 1 times.
|
2 | int color = (idx == 0) ? kBlack : kRed; |
81 | |||
82 |
2/4✓ Branch 0 (43→44) taken 2 times.
✗ Branch 1 (43→76) not taken.
✓ Branch 2 (44→45) taken 2 times.
✗ Branch 3 (44→76) not taken.
|
2 | ConfigureHistogram(h_Mgg[idx], color); |
83 |
2/4✓ Branch 0 (45→46) taken 2 times.
✗ Branch 1 (45→76) not taken.
✓ Branch 2 (46→47) taken 2 times.
✗ Branch 3 (46→76) not taken.
|
2 | ConfigureHistogram(h_P[idx], color); |
84 |
2/4✓ Branch 0 (47→48) taken 2 times.
✗ Branch 1 (47→76) not taken.
✓ Branch 2 (48→49) taken 2 times.
✗ Branch 3 (48→76) not taken.
|
2 | ConfigureHistogram(h_Th[idx], color); |
85 |
2/4✓ Branch 0 (49→50) taken 2 times.
✗ Branch 1 (49→76) not taken.
✓ Branch 2 (50→51) taken 2 times.
✗ Branch 3 (50→76) not taken.
|
2 | ConfigureHistogram(h_Phi[idx], color); |
86 | } | ||
87 |
0/2✗ Branch 0 (60→61) not taken.
✗ Branch 1 (60→63) 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 (14→3) taken 1982 times.
✓ Branch 1 (14→23) 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 (9→10) not taken.
✓ Branch 1 (9→11) taken 1982 times.
|
3964 | h_Phi.at(idx)->Fill(photon.Phi() * 180.0 / M_PI); |
102 | } | ||
103 | |||
104 |
2/2✓ Branch 0 (23→15) taken 1982 times.
✓ Branch 1 (23→24) taken 2000 times.
|
3982 | for (size_t i = 0; i < photons.size(); ++i) { |
105 |
2/2✓ Branch 0 (22→16) taken 2014 times.
✓ Branch 1 (22→23) 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 (6→7) taken 1 times.
✗ Branch 1 (6→51) not taken.
|
2 | if(GetOutputDirectory()){ |
115 | int n_rows = 2; | ||
116 | int n_cols = 2; | ||
117 |
1/2✓ Branch 0 (8→9) taken 1 times.
✗ Branch 1 (8→52) 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 (41→12) taken 4 times.
✓ Branch 1 (41→42) 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 (19→20) taken 1 times.
✓ Branch 1 (19→25) taken 1 times.
✓ Branch 2 (19→30) taken 1 times.
✓ Branch 3 (19→35) 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 (45→46) taken 1 times.
✗ Branch 1 (45→54) 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 |