CMS 3D CMS Logo

L1TUtmTriggerMenuPayloadInspectorHelper.h
Go to the documentation of this file.
1 #ifndef CondCore_L1TPlugins_L1TUtmTriggerMenuPayloadInspectorHelper_H
2 #define CondCore_L1TPlugins_L1TUtmTriggerMenuPayloadInspectorHelper_H
3 
4 #include "TH1.h"
5 #include "TH2.h"
6 #include "TStyle.h"
7 #include "TCanvas.h"
8 #include "TLatex.h"
9 #include "TLine.h"
10 
12 
14 
15  using l1tUtmAlgoMap = std::map<std::string, L1TUtmAlgorithm>;
16  using l1tUtmConditionMap = std::map<std::string, L1TUtmCondition>;
17 
19  public:
20  // constructor
21  L1UtmTriggerMenuInfo(const L1TUtmTriggerMenu* l1utmMenu) { m_map = l1utmMenu->getAlgorithmMap(); }
22 
23  // destructor
24  ~L1UtmTriggerMenuInfo() = default;
25 
26  public:
27  const std::vector<std::string> listOfAlgos() const {
28  std::vector<std::string> output;
29  std::transform(m_map.begin(),
30  m_map.end(),
31  std::back_inserter(output),
32  [](const std::pair<std::string, L1TUtmAlgorithm>& pair) {
33  return pair.first; // Extracting the string key using lambda
34  });
35  return output;
36  }
37 
38  //___________________________________________________________________
39  const std::vector<std::string> listOfCommonAlgos(const L1TUtmTriggerMenu* other) const {
40  const auto& otherMap = other->getAlgorithmMap();
41 
42  std::vector<std::string> commonKeys;
43 
44  // Lambda function to find common keys and store them in commonKeys vector
45  std::for_each(
46  m_map.begin(), m_map.end(), [&commonKeys, &otherMap](const std::pair<std::string, L1TUtmAlgorithm>& pair) {
47  const std::string& key = pair.first;
48 
49  // Check if the key exists in map2
50  if (otherMap.find(key) != otherMap.end()) {
51  commonKeys.push_back(key);
52  }
53  });
54  return commonKeys;
55  }
56 
57  //___________________________________________________________________
58  const std::vector<std::string> onlyInThis(const L1TUtmTriggerMenu* other) const {
59  const auto& otherMap = other->getAlgorithmMap();
60 
61  std::vector<std::string> stringsOnlyInFirstMap;
62 
63  // Lambda function to extract only the strings present in m_map but not in otherMap
64  std::for_each(m_map.begin(),
65  m_map.end(),
66  [&stringsOnlyInFirstMap, &otherMap](const std::pair<std::string, L1TUtmAlgorithm>& pair) {
67  const std::string& key = pair.first;
68  // Check if the key exists in otherMap
69  if (otherMap.find(key) == otherMap.end()) {
70  stringsOnlyInFirstMap.push_back(key); // Add key to the vector
71  }
72  });
73 
74  return stringsOnlyInFirstMap;
75  }
76 
77  //___________________________________________________________________
78  const std::vector<std::string> onlyInOther(const L1TUtmTriggerMenu* other) const {
79  const auto& otherMap = other->getAlgorithmMap();
80 
81  std::vector<std::string> stringsOnlyInSecondMap;
82 
83  // Lambda function capturing 'this' to access the member variable 'm_map'
84  std::for_each(otherMap.begin(),
85  otherMap.end(),
86  [this, &stringsOnlyInSecondMap](const std::pair<std::string, L1TUtmAlgorithm>& pair) {
87  const std::string& key = pair.first;
88 
89  // Check if the key exists in m_map
90  if (this->m_map.find(key) == this->m_map.end()) {
91  stringsOnlyInSecondMap.push_back(key); // Add key to the vector
92  }
93  });
94 
95  return stringsOnlyInSecondMap;
96  }
97 
98  private:
100  };
101 
103  public:
105  : m_info(thisMenu), m_tagName(theTag), m_IOVsinceDisplay(theIOV) {}
106  ~L1TUtmTriggerMenuDisplay() = default;
107 
108  void setImageFileName(const std::string& theFileName) {
109  m_imageFileName = theFileName;
110  return;
111  }
112 
113  //___________________________________________________________________
115  const auto& vec_only_in_this = m_info.onlyInThis(other);
116  const auto& vec_only_in_other = m_info.onlyInOther(other);
117 
118  // preparations for plotting
119  // starting table at y=1.0 (top of the canvas)
120  // first column is at 0.03, second column at 0.22 NDC
121  unsigned int mapsize = vec_only_in_this.size() + vec_only_in_other.size();
122  float pitch = 1. / (mapsize * 1.1);
123  float y, x1, x2;
124  std::vector<float> y_x1, y_x2, y_line;
125  std::vector<std::string> s_x1, s_x2, s_x3;
126  y = 1.0;
127  x1 = 0.02;
128  x2 = x1 + 0.45;
129  y -= pitch;
130 
131  // title for plot
132  y_x1.push_back(y);
133  s_x1.push_back("#scale[1.1]{Key}");
134  y_x2.push_back(y);
135  s_x2.push_back("#scale[1.1]{Target tag / IOV: #color[2]{" + m_tagName + "} / " + m_IOVsinceDisplay + "}");
136 
137  y -= pitch;
138  y_x1.push_back(y);
139  s_x1.push_back("");
140  y_x2.push_back(y);
141  s_x2.push_back("#scale[1.1]{Refer tag / IOV: #color[4]{" + theRefTag + "} / " + theRefIOV + "}");
142 
143  y -= pitch / 2.;
144  y_line.push_back(y);
145 
146  // First, check if there are records in reference which are not in target
147  for (const auto& ref : vec_only_in_other) {
148  y -= pitch;
149  y_x1.push_back(y);
150  s_x1.push_back(ref);
151  y_x2.push_back(y);
152  s_x2.push_back("#color[4]{#bf{Only in reference, not in target.}}");
153  y_line.push_back(y - (pitch / 2.));
154  }
155 
156  // Second, check if there are records in target which are not in reference
157  for (const auto& tar : vec_only_in_this) {
158  y -= pitch;
159  y_x1.push_back(y);
160  s_x1.push_back(tar);
161  y_x2.push_back(y);
162  s_x2.push_back("#color[2]{#bf{Only in target, not in reference.}}");
163  y_line.push_back(y - (pitch / 2.));
164  }
165 
166  // Finally, print text to TCanvas
167  TCanvas canvas("L1TUtmMenuData", "L1TUtmMenuData", 2000, std::max(y_x1.size(), y_x2.size()) * 40);
168  TLatex l;
169  // Draw the columns titles
170  l.SetTextAlign(12);
171 
172  float newpitch = 1 / (std::max(y_x1.size(), y_x2.size()) * 1.1);
173  float factor = newpitch / pitch;
174  l.SetTextSize(newpitch - 0.002);
175  canvas.cd();
176  for (unsigned int i = 0; i < y_x1.size(); i++) {
177  l.DrawLatexNDC(x1, 1 - (1 - y_x1[i]) * factor, s_x1[i].c_str());
178  }
179 
180  for (unsigned int i = 0; i < y_x2.size(); i++) {
181  l.DrawLatexNDC(x2, 1 - (1 - y_x2[i]) * factor, s_x2[i].c_str());
182  }
183 
184  canvas.cd();
185  canvas.Update();
186 
187  // Draw horizontal lines separating records
188  TLine lines[y_line.size()];
189  unsigned int iL = 0;
190  for (const auto& line : y_line) {
191  lines[iL] = TLine(gPad->GetUxmin(), 1 - (1 - line) * factor, gPad->GetUxmax(), 1 - (1 - line) * factor);
192  lines[iL].SetLineWidth(1);
193  lines[iL].SetLineStyle(9);
194  lines[iL].SetLineColor(2);
195  lines[iL].Draw("same");
196  iL++;
197  }
198 
199  std::string fileName("L1UtmMenuData_Compare.png");
200  if (!m_imageFileName.empty())
202  canvas.SaveAs(fileName.c_str());
203  }
204 
205  private:
210  };
211 } // namespace L1TUtmTriggerMenuInspectorHelper
212 
213 #endif
const std::vector< std::string > onlyInOther(const L1TUtmTriggerMenu *other) const
const std::vector< std::string > onlyInThis(const L1TUtmTriggerMenu *other) const
const std::vector< std::string > listOfCommonAlgos(const L1TUtmTriggerMenu *other) const
L1TUtmTriggerMenuDisplay(const L1TUtmTriggerMenu *thisMenu, std::string theTag, std::string theIOV)
L1UtmTriggerMenuInfo m_info
map of the record / metadata associations
std::map< std::string, L1TUtmCondition > l1tUtmConditionMap
key
prepare the HTCondor submission files and eventually submit them
void plotDiffWithOtherMenu(const L1TUtmTriggerMenu *other, std::string theRefTag, std::string theRefIOV)
def canvas(sub, attr)
Definition: svgfig.py:482
Definition: output.py:1
const std::map< std::string, L1TUtmAlgorithm > & getAlgorithmMap() const
std::map< std::string, L1TUtmAlgorithm > l1tUtmAlgoMap
unsigned transform(const HcalDetId &id, unsigned transformCode)