10 #include <dqm/analysis/modules/DQMHistAnalysisHLTModule.h>
11 #include <framework/core/ModuleParam.templateDetails.h>
14 #include <hlt/softwaretrigger/modules/dqm/SoftwareTriggerHLTDQMModule.h>
20 bool hasValue(
const std::string& name, TH1* histogram)
22 return histogram->GetXaxis()->FindFixBin(name.c_str()) != -1;
25 double getValue(
const std::string& name, TH1* histogram)
27 B2ASSERT(
"This histogram does not have this value!", hasValue(name, histogram));
28 auto binNumber = histogram->GetXaxis()->FindFixBin(name.c_str());
29 return histogram->GetBinContent(binNumber);
35 DQMHistAnalysisHLTModule::DQMHistAnalysisHLTModule()
37 addParam(
"pvPrefix", m_pvPrefix,
"EPICS PV Name for the inst. luminosity", m_pvPrefix);
38 addParam(
"bhabhaName", m_bhabhaName,
"Name of the bhabha trigger to do a ratio against", m_bhabhaName);
39 addParam(
"columnMapping", m_columnMapping,
"Which columns to use for calculating ratios and cross sections", m_columnMapping);
40 addParam(
"l1Histograms", m_l1Histograms,
"Which l1 histograms to show", m_l1Histograms);
41 addParam(
"retentionPerUnit", m_retentionPerUnit,
"Which HLT filter lines to use for calculation retention rate per unit",
45 void DQMHistAnalysisHLTModule::initialize()
51 new TCanvas(
"HLT/Ratio"),
52 new TH1F(
"Ratio",
"Ratio of Tags to HLT triggered events", 1, 0, 0)
54 m_hEfficiencyTotal = {
55 new TCanvas(
"HLT/RatioTotal"),
56 new TH1F(
"Ratio",
"Ratio of Tags to all events", 1, 0, 0)
59 new TCanvas(
"HLT/CrossSection"),
60 new TH1F(
"CrossSection",
"Cross Section of triggered Events", 1, 0, 0)
63 new TCanvas(
"HLT/RatioToBahbha"),
64 new TH1F(
"RatioToBahbha",
"Ratio to bhabha events", 1, 0, 0)
67 for (
const std::string& l1Name : m_l1Histograms) {
68 m_hl1Ratios.emplace(l1Name, std::make_pair(
69 new TCanvas((
"HLT/" + l1Name +
"RatioToL1").c_str()),
71 new TH1F((l1Name +
"RatioToL1").c_str(), (
"HLT Fractions for L1 " + l1Name).c_str(), 1, 0, 0)
75 for (
const std::string& filterLine : m_retentionPerUnit) {
76 m_hRetentionPerUnit.emplace(filterLine, std::make_pair(
77 new TCanvas((
"HLT/" + filterLine +
"_RetentionPerUnit").c_str()),
78 new TH1F((filterLine +
"_RetentionPerUnit").c_str(), (
"Retention rate per unit of: " + filterLine).c_str(),
79 SoftwareTrigger::HLTUnit::max_hlt_units, 1,
80 SoftwareTrigger::HLTUnit::max_hlt_units + 1)
84 for (
auto& canvasAndHisto : {m_hEfficiencyTotal, m_hEfficiency, m_hCrossSection, m_hRatios}) {
85 auto* histogram = canvasAndHisto.second;
86 histogram->SetDirectory(0);
87 histogram->SetOption(
"bar");
88 histogram->SetFillStyle(0);
89 histogram->SetStats(
false);
90 histogram->Draw(
"hist");
93 for (
auto& nameAndcanvasAndHisto : m_hl1Ratios) {
94 auto* histogram = nameAndcanvasAndHisto.second.second;
95 histogram->SetDirectory(0);
96 histogram->SetOption(
"bar");
97 histogram->SetFillStyle(0);
98 histogram->SetStats(
false);
99 histogram->Draw(
"hist");
102 for (
auto& nameAndcanvasAndHisto : m_hRetentionPerUnit) {
103 auto* histogram = nameAndcanvasAndHisto.second.second;
104 histogram->SetDirectory(0);
105 histogram->SetOption(
"bar");
106 histogram->SetFillStyle(0);
107 histogram->SetStats(
false);
108 histogram->Draw(
"hist");
112 if (not m_pvPrefix.empty()) {
113 SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
114 SEVCHK(ca_create_channel(m_pvPrefix.data(), NULL, NULL, 10, &m_epicschid),
"ca_create_channel failure");
115 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
121 void DQMHistAnalysisHLTModule::beginRun()
123 for (
auto& canvasAndHisto : {m_hEfficiencyTotal, m_hEfficiency, m_hCrossSection, m_hRatios}) {
124 auto* canvas = canvasAndHisto.first;
128 for (
auto& nameAndcanvasAndHisto : m_hl1Ratios) {
129 auto* canvas = nameAndcanvasAndHisto.second.first;
133 for (
auto& nameAndcanvasAndHisto : m_hRetentionPerUnit) {
134 auto* canvas = nameAndcanvasAndHisto.second.first;
139 void DQMHistAnalysisHLTModule::event()
141 auto* filterHistogram = findHist(
"softwaretrigger/filter");
142 auto* skimHistogram = findHist(
"softwaretrigger/skim");
143 auto* totalResultHistogram = findHist(
"softwaretrigger/total_result");
144 auto* hltUnitNumberHistogram = findHist(
"softwaretrigger_before_filter/hlt_unit_number");
146 if (not filterHistogram) {
147 B2ERROR(
"Can not find the filter histogram!");
150 if (not skimHistogram) {
151 B2ERROR(
"Can not find the skim histogram!");
154 if (not totalResultHistogram) {
155 B2ERROR(
"Can not find the total result histogram!");
158 if (not hltUnitNumberHistogram) {
159 B2ERROR(
"Can not find the HLT unit number histogram!");
163 m_hEfficiencyTotal.second->Reset();
164 m_hEfficiency.second->Reset();
165 m_hCrossSection.second->Reset();
166 m_hRatios.second->Reset();
168 double instLuminosity = 0;
169 double numberOfAcceptedHLTEvents = getValue(
"total_result", totalResultHistogram);
170 double numberOfBhabhaEvents = getValue(m_bhabhaName, skimHistogram);
171 double numberOfAllEvents = hltUnitNumberHistogram->GetEntries();
174 if (not m_pvPrefix.empty()) {
175 if (!ca_current_context()) SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
176 SEVCHK(ca_get(DBR_DOUBLE, m_epicschid, (
void*)&instLuminosity),
"ca_get failure");
177 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
183 m_hEfficiencyTotal.second->Fill(
"total_result", numberOfAcceptedHLTEvents / numberOfAllEvents);
184 if (instLuminosity != 0) {
185 m_hCrossSection.second->Fill(
"total_result", numberOfAcceptedHLTEvents / numberOfAllEvents * instLuminosity);
187 m_hRatios.second->Fill(
"total_result", numberOfAcceptedHLTEvents / numberOfBhabhaEvents);
189 for (
const auto& columnMapping : m_columnMapping) {
190 const auto& from = columnMapping.first;
191 const auto& to = columnMapping.second;
194 if (hasValue(from, filterHistogram)) {
195 value = getValue(from, filterHistogram);
196 }
else if (hasValue(from, skimHistogram)) {
197 value = getValue(from, skimHistogram);
199 B2ERROR(
"Can not find value " << from <<
". Will not use it!");
203 m_hEfficiency.second->Fill(to.c_str(), value / numberOfAcceptedHLTEvents);
204 m_hEfficiencyTotal.second->Fill(to.c_str(), value / numberOfAllEvents);
205 if (instLuminosity != 0) {
206 m_hCrossSection.second->Fill(to.c_str(), value / numberOfAllEvents * instLuminosity);
208 m_hRatios.second->Fill(to.c_str(), value / numberOfBhabhaEvents);
211 for (
const std::string& l1Name : m_l1Histograms) {
212 auto* histogram = m_hl1Ratios.at(l1Name).second;
215 auto* l1Histogram = findHist(
"softwaretrigger/" + l1Name);
216 auto* l1TotalResultHistogram = findHist(
"softwaretrigger/l1_total_result");
218 if (not l1Histogram or not l1TotalResultHistogram) {
219 B2ERROR(
"Can not find L1 histograms from softwaretrigger!");
223 for (
const auto& columnMapping : m_columnMapping) {
224 const auto& from = columnMapping.first;
225 const auto& to = columnMapping.second;
227 if (not hasValue(from, l1Histogram)) {
228 B2ERROR(
"Can not find label " << from <<
" in l1 histogram " << l1Name);
232 if (not hasValue(l1Name, l1TotalResultHistogram)) {
233 B2ERROR(
"Can not find label " << l1Name <<
" in l1 total result histogram");
237 const double hltValueInL1Bin = getValue(from, l1Histogram);
238 const double l1TotalResult = getValue(l1Name, l1TotalResultHistogram);
240 histogram->Fill(to.c_str(), hltValueInL1Bin / l1TotalResult);
244 const auto from =
"hlt_result";
245 const auto to =
"hlt_result";
247 if (not hasValue(from, l1Histogram)) {
248 B2ERROR(
"Can not find label " << from <<
" in l1 histogram " << l1Name);
252 if (not hasValue(l1Name, l1TotalResultHistogram)) {
253 B2ERROR(
"Can not find label " << l1Name <<
" in l1 total result histogram");
257 const double hltValueInL1Bin = getValue(from, l1Histogram);
258 const double l1TotalResult = getValue(l1Name, l1TotalResultHistogram);
260 histogram->Fill(to, hltValueInL1Bin / l1TotalResult);
263 for (
const std::string& filterLine : m_retentionPerUnit) {
264 auto* histogram = m_hRetentionPerUnit.at(filterLine).second;
267 auto* filterLineHistogram = findHist(
"softwaretrigger/" + filterLine +
"_per_unit");
269 if (not filterLineHistogram) {
270 B2ERROR(
"Can not find " << filterLineHistogram <<
"_per_event histograms from softwaretrigger!");
274 for (
unsigned int i = 1; i <= SoftwareTrigger::HLTUnit::max_hlt_units; i++) {
275 double totalUnitValue = hltUnitNumberHistogram->GetBinContent(i);
276 if (totalUnitValue == 0) {
277 histogram->Fill(i, 0);
279 double filterLineUnitValue = filterLineHistogram->GetBinContent(i);
280 histogram->Fill(i, filterLineUnitValue / totalUnitValue);
285 for (
auto& canvasAndHisto : {m_hEfficiencyTotal, m_hEfficiency, m_hCrossSection, m_hRatios}) {
286 auto* canvas = canvasAndHisto.first;
287 auto* histogram = canvasAndHisto.second;
290 histogram->LabelsDeflate(
"X");
291 histogram->Draw(
"hist");
296 for (
auto& nameAndCanvasAndHisto : m_hl1Ratios) {
297 auto* canvas = nameAndCanvasAndHisto.second.first;
298 auto* histogram = nameAndCanvasAndHisto.second.second;
301 histogram->LabelsDeflate(
"X");
302 histogram->Draw(
"hist");
307 for (
auto& nameAndCanvasAndHisto : m_hRetentionPerUnit) {
308 auto* canvas = nameAndCanvasAndHisto.second.first;
309 auto* histogram = nameAndCanvasAndHisto.second.second;
312 histogram->Draw(
"hist");