@@ -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
0 commit comments