Skip to content

Commit b1ca820

Browse files
committed
improve pagination of L1TUtmTriggerMenuPayloadInspector plots
1 parent 3914bc8 commit b1ca820

File tree

2 files changed

+65
-70
lines changed

2 files changed

+65
-70
lines changed

CondCore/L1TPlugins/interface/L1TUtmTriggerMenuPayloadInspectorHelper.h

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,20 @@ namespace L1TUtmTriggerMenuInspectorHelper {
159159
const auto& vec_only_in_this = m_info.template onlyInThis<T>(other);
160160
const auto& vec_only_in_other = m_info.template onlyInOther<T>(other);
161161

162-
// preparations for plotting
163-
// starting table at y=1.0 (top of the canvas)
164-
// first column is at 0.03, second column at 0.22 NDC
162+
// Calculate the total number of entries
165163
unsigned int mapsize = vec_only_in_this.size() + vec_only_in_other.size();
166-
float pitch = 1. / (mapsize * 1.1);
167-
float y, x1, x2;
164+
165+
// Dynamically calculate the pitch based on the number of entries
166+
float canvasHeight = std::max(800.0f, mapsize * 30.0f); // Adjust canvas height based on the number of entries
167+
float pitch = 1.0 / (mapsize + 3.0); // Pitch for spacing between lines (extra space for headers)
168+
169+
float y = 1.0;
170+
float x1 = 0.02, x2 = x1 + 0.37;
168171
std::vector<float> y_x1, y_x2, y_line;
169-
std::vector<std::string> s_x1, s_x2, s_x3;
170-
y = 1.0;
171-
x1 = 0.02;
172-
x2 = x1 + 0.37;
173-
y -= pitch;
172+
std::vector<std::string> s_x1, s_x2;
174173

175-
// title for plot
174+
// Title for plot
175+
y -= pitch;
176176
y_x1.push_back(y);
177177
s_x1.push_back(getLabel());
178178
y_x2.push_back(y);
@@ -184,65 +184,61 @@ namespace L1TUtmTriggerMenuInspectorHelper {
184184
y_x2.push_back(y);
185185
s_x2.push_back("#scale[1.1]{Refer tag / IOV: #color[4]{" + theRefTag + "} / " + theRefIOV + "}");
186186

187-
y -= pitch / 2.;
187+
y -= pitch / 2.0;
188188
y_line.push_back(y);
189189

190-
// First, check if there are records in reference which are not in target
190+
// Records only in reference (not in target)
191191
for (const auto& ref : vec_only_in_other) {
192192
y -= pitch;
193193
y_x1.push_back(y);
194194
s_x1.push_back("#scale[0.7]{" + ref + "}");
195195
y_x2.push_back(y);
196196
s_x2.push_back("#color[4]{#bf{Only in reference, not in target.}}");
197-
y_line.push_back(y - (pitch / 2.));
197+
y_line.push_back(y - (pitch / 2.0));
198198
}
199199

200-
// Second, check if there are records in target which are not in reference
200+
// Records only in target (not in reference)
201201
for (const auto& tar : vec_only_in_this) {
202202
y -= pitch;
203203
y_x1.push_back(y);
204204
s_x1.push_back("#scale[0.7]{" + tar + "}");
205205
y_x2.push_back(y);
206206
s_x2.push_back("#color[2]{#bf{Only in target, not in reference.}}");
207-
y_line.push_back(y - (pitch / 2.));
207+
y_line.push_back(y - (pitch / 2.0));
208208
}
209209

210-
// Finally, print text to TCanvas
211-
TCanvas canvas("L1TUtmMenuData", "L1TUtmMenuData", 2000, std::max(y_x1.size(), y_x2.size()) * 40);
210+
// Adjust canvas size dynamically
211+
TCanvas canvas("L1TUtmMenuData", "L1TUtmMenuData", 2000, static_cast<int>(canvasHeight));
212212
TLatex l;
213-
// Draw the columns titles
214213
l.SetTextAlign(12);
215214

216-
float newpitch = 1 / (std::max(y_x1.size(), y_x2.size()) * 1.1);
217-
float factor = newpitch / pitch;
218-
l.SetTextSize(newpitch - 0.002);
215+
// Set the text size dynamically based on pitch
216+
float textSize = std::clamp(pitch, 0.015f, 0.035f);
217+
l.SetTextSize(textSize);
218+
219219
canvas.cd();
220220
for (unsigned int i = 0; i < y_x1.size(); i++) {
221-
l.DrawLatexNDC(x1, 1 - (1 - y_x1[i]) * factor, s_x1[i].c_str());
221+
l.DrawLatexNDC(x1, y_x1[i], s_x1[i].c_str());
222222
}
223-
224223
for (unsigned int i = 0; i < y_x2.size(); i++) {
225-
l.DrawLatexNDC(x2, 1 - (1 - y_x2[i]) * factor, s_x2[i].c_str());
224+
l.DrawLatexNDC(x2, y_x2[i], s_x2[i].c_str());
226225
}
227226

228-
canvas.cd();
229-
canvas.Update();
230-
231227
// Draw horizontal lines separating records
232228
TLine lines[y_line.size()];
233-
unsigned int iL = 0;
234-
for (const auto& line : y_line) {
235-
lines[iL] = TLine(gPad->GetUxmin(), 1 - (1 - line) * factor, gPad->GetUxmax(), 1 - (1 - line) * factor);
236-
lines[iL].SetLineWidth(1);
237-
lines[iL].SetLineStyle(9);
238-
lines[iL].SetLineColor(2);
239-
lines[iL].Draw("same");
240-
iL++;
229+
for (unsigned int i = 0; i < y_line.size(); i++) {
230+
lines[i] = TLine(gPad->GetUxmin(), y_line[i], gPad->GetUxmax(), y_line[i]);
231+
lines[i].SetLineWidth(1);
232+
lines[i].SetLineStyle(9);
233+
lines[i].SetLineColor(2);
234+
lines[i].Draw("same");
241235
}
242236

243-
std::string fileName("L1UtmMenuData_Compare.png");
244-
if (!m_imageFileName.empty())
237+
// Save the canvas as an image
238+
std::string fileName = "L1UtmMenuData_Compare.png";
239+
if (!m_imageFileName.empty()) {
245240
fileName = m_imageFileName;
241+
}
246242
canvas.SaveAs(fileName.c_str());
247243
}
248244

CondCore/L1TPlugins/plugins/L1TUtmTriggerMenu_PayloadInspector.cc

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,73 +45,72 @@ namespace {
4545
std::string IOVsince = std::to_string(std::get<0>(iov));
4646
auto tagname = tag.name;
4747
std::shared_ptr<L1TUtmTriggerMenu> payload = fetchPayload(std::get<1>(iov));
48+
4849
if (payload.get()) {
49-
/// Create a canvas
5050
const auto& theMap = payload->getAlgorithmMap();
51-
5251
unsigned int mapsize = theMap.size();
53-
float pitch = 1. / (mapsize);
5452

55-
float y, x1, x2;
56-
std::vector<float> y_x1, y_x2, y_line;
57-
std::vector<std::string> s_x1, s_x2, s_x3;
53+
// Dynamically calculate the pitch and canvas height
54+
float canvasHeight = std::max(800.0f, mapsize * 30.0f); // Adjust canvas height based on entries
55+
float pitch = 1.0 / (mapsize + 2.0); // Adjusted pitch for better spacing
5856

59-
// starting table at y=1.0 (top of the canvas)
60-
// first column is at 0.02, second column at 0.32 NDC
61-
y = 1.0;
62-
x1 = 0.02;
63-
x2 = x1 + 0.15;
57+
float y = 1.0;
58+
float x1 = 0.02, x2 = x1 + 0.15;
59+
std::vector<float> y_x1, y_x2, y_line;
60+
std::vector<std::string> s_x1, s_x2;
6461

62+
// Title for the plot
6563
y -= pitch;
6664
y_x1.push_back(y);
6765
s_x1.push_back("#scale[1.2]{Algo Name}");
6866
y_x2.push_back(y);
6967
s_x2.push_back("#scale[1.2]{tag: " + tag.name + " in IOV: " + IOVsince + "}");
7068

71-
y -= pitch / 2.;
69+
y -= pitch / 2.0;
7270
y_line.push_back(y);
7371

72+
// Populate the content
7473
for (const auto& [name, algo] : theMap) {
7574
y -= pitch;
7675
y_x1.push_back(y);
7776
s_x1.push_back("''");
78-
7977
y_x2.push_back(y);
8078
s_x2.push_back("#color[2]{" + name + "}");
81-
y_line.push_back(y - (pitch / 2.));
79+
y_line.push_back(y - (pitch / 2.0));
8280
}
8381

84-
TCanvas canvas("L1TriggerAlgos", "L1TriggerAlgos", 2000, mapsize * 40);
82+
// Dynamically adjust canvas size
83+
TCanvas canvas("L1TriggerAlgos", "L1TriggerAlgos", 2000, static_cast<int>(canvasHeight));
8584
TLatex l;
86-
// Draw the columns titles
8785
l.SetTextAlign(12);
88-
l.SetTextSize(pitch * 10);
86+
87+
// Set the text size dynamically based on pitch
88+
float textSize = std::clamp(pitch * 10.0f, 0.015f, 0.035f);
89+
l.SetTextSize(textSize);
90+
91+
// Draw the columns
8992
canvas.cd();
9093
for (unsigned int i = 0; i < y_x1.size(); i++) {
91-
l.DrawLatexNDC(x1, 1 - (1 - y_x1[i]), s_x1[i].c_str());
94+
l.DrawLatexNDC(x1, y_x1[i], s_x1[i].c_str());
9295
}
93-
9496
for (unsigned int i = 0; i < y_x2.size(); i++) {
95-
l.DrawLatexNDC(x2, 1 - (1 - y_x2[i]), s_x2[i].c_str());
97+
l.DrawLatexNDC(x2, y_x2[i], s_x2[i].c_str());
9698
}
9799

98-
canvas.cd();
99-
canvas.Update();
100-
100+
// Draw horizontal lines separating records
101101
TLine lines[y_line.size()];
102-
unsigned int iL = 0;
103-
for (const auto& line : y_line) {
104-
lines[iL] = TLine(gPad->GetUxmin(), 1 - (1 - line), gPad->GetUxmax(), 1 - (1 - line));
105-
lines[iL].SetLineWidth(1);
106-
lines[iL].SetLineStyle(9);
107-
lines[iL].SetLineColor(2);
108-
lines[iL].Draw("same");
109-
iL++;
102+
for (unsigned int i = 0; i < y_line.size(); i++) {
103+
lines[i] = TLine(gPad->GetUxmin(), y_line[i], gPad->GetUxmax(), y_line[i]);
104+
lines[i].SetLineWidth(1);
105+
lines[i].SetLineStyle(9);
106+
lines[i].SetLineColor(2);
107+
lines[i].Draw("same");
110108
}
111109

110+
// Save the canvas as an image
112111
std::string fileName(m_imageFileName);
113112
canvas.SaveAs(fileName.c_str());
114-
} // payload
113+
}
115114
return true;
116115
} // fill
117116
};

0 commit comments

Comments
 (0)