Repository navigation
Expand file tree
/
Copy pathOutOfBunchCollFeeModulesCheck.cxx
More file actions
171 lines (151 loc) · 6.26 KB
/
Copy pathOutOfBunchCollFeeModulesCheck.cxx
File metadata and controls
171 lines (151 loc) · 6.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Copyright 2023 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
///
/// \file OutOfBunchCollFeeModulesCheck.cxx
/// \author Dawid Skora dawid.mateusz.skora@cern.ch
///
#include "FV0/OutOfBunchCollFeeModulesCheck.h"
#include "QualityControl/MonitorObject.h"
#include "QualityControl/Quality.h"
#include "QualityControl/QcInfoLogger.h"
#include "DataFormatsParameters/GRPLHCIFData.h"
// ROOT
#include <TH1.h>
#include <TH2.h>
#include <TPaveText.h>
#include <TLine.h>
#include <TList.h>
#include <map>
#include <algorithm>
#include <DataFormatsQualityControl/FlagType.h>
#include <DataFormatsQualityControl/FlagTypeFactory.h>
#include "CommonConstants/LHCConstants.h"
using namespace std;
using namespace o2::quality_control;
namespace o2::quality_control_modules::fv0
{
void OutOfBunchCollFeeModulesCheck::configure()
{
if (auto param = mCustomParameters.find("thresholdWarning"); param != mCustomParameters.end()) {
mThreshWarning = stof(param->second);
ILOG(Debug, Support) << "configure() : using thresholdWarning = " << mThreshWarning << ENDM;
} else {
mThreshWarning = 1e-3;
ILOG(Debug, Support) << "configure() : using default thresholdWarning = " << mThreshWarning << ENDM;
}
if (auto param = mCustomParameters.find("thresholdError"); param != mCustomParameters.end()) {
mThreshError = stof(param->second);
ILOG(Debug, Support) << "configure() : using thresholdError = " << mThreshError << ENDM;
} else {
mThreshError = 0.1;
ILOG(Debug, Support) << "configure() : using default thresholdError = " << mThreshError << ENDM;
}
if (mThreshError < mThreshWarning) {
ILOG(Debug, Support) << "thresholdError lower than thresholdWarning. Swaping values." << ENDM;
std::swap(mThreshError, mThreshWarning);
}
}
Quality OutOfBunchCollFeeModulesCheck::check(std::map<std::string, std::shared_ptr<MonitorObject>>* moMap)
{
Quality result = Quality::Null;
for (auto& [moName, mo] : *moMap) {
(void)moName;
if (mo->getName().find("OutOfBunchColl_BCvsFeeModules") != std::string::npos) {
auto* histogram = dynamic_cast<TH2*>(mo->getObject());
if (!histogram) {
ILOG(Error, Support) << "check(): MO " << mo->getName() << " not found" << ENDM;
result.addFlag(FlagTypeFactory::Unknown(), "MO " + mo->getName() + " not found");
result.set(Quality::Null);
return result;
}
std::vector<float> allCollPerFeeModule(mo->getMetadataMap().size() + 1, 0);
int parsedBins = 0;
const int numberOfModules = histogram->GetNbinsY();
for (auto metainfo : mo->getMetadataMap()) {
int bin = 0;
float value = 0;
const char* metaInfoKey = metainfo.first.data();
const char* metaInfoKeyEnd = metainfo.first.data() + metainfo.first.size();
if (std::from_chars(metaInfoKey, metaInfoKeyEnd, bin).ptr == metaInfoKeyEnd) {
if (bin >= 0 && bin <= numberOfModules) {
try {
value = std::stof(metainfo.second);
} catch (std::invalid_argument& e) {
ILOG(Warning, Support) << "Value " << value << " in bin " << bin << " is not convertible to float. Skipping." << ENDM;
continue;
}
parsedBins++;
allCollPerFeeModule[bin] = value;
}
}
}
if (parsedBins != histogram->GetNbinsY()) {
ILOG(Warning, Support) << "Missing bins in OutOfBunchColl_BCvsFeeModules: expected " << histogram->GetNbinsY() << ", get " << parsedBins << ENDM;
}
// Calculate out-of-bunch-coll fraction for Fee Modules
for (int binY = 1; binY <= histogram->GetNbinsY(); binY++) {
auto outOfBcCollisions = histogram->Integral(1, sBCperOrbit, binY, binY);
float fraction = 0;
if (allCollPerFeeModule[binY]) {
fraction = outOfBcCollisions / allCollPerFeeModule[binY];
}
if (fraction > mFractionOutOfBunchColl) {
mFractionOutOfBunchColl = fraction;
}
}
// Check the biggest fraction of out-of-bunch-coll
if (mFractionOutOfBunchColl > mThreshError) {
result.set(Quality::Bad);
result.addFlag(FlagTypeFactory::Unknown(),
Form("Fraction of out of bunch collisions (%.2e) is above \"Error\" threshold (%.2e)",
mFractionOutOfBunchColl, mThreshError));
} else if (mFractionOutOfBunchColl > mThreshWarning) {
result.set(Quality::Medium);
result.addFlag(FlagTypeFactory::Unknown(),
Form("Fraction of out of bunch collisions (%.2e) is above \"Warning\" threshold (%.2e)",
mFractionOutOfBunchColl, mThreshWarning));
} else {
result.set(Quality::Good);
}
}
}
return result;
}
void OutOfBunchCollFeeModulesCheck::beautify(std::shared_ptr<MonitorObject> mo, Quality checkResult)
{
if (mo->getName().find("OutOfBunchColl_BCvsFeeModules") != std::string::npos) {
auto* histogram = dynamic_cast<TH2*>(mo->getObject());
if (!histogram) {
ILOG(Error, Support) << "beautify(): MO " << mo->getName() << " not found" << ENDM;
return;
}
TPaveText* msg = new TPaveText(0.1, 0.85, 0.9, 0.9, "NDC");
histogram->GetListOfFunctions()->Add(msg);
msg->SetName(Form("%s_msg", mo->GetName()));
msg->Clear();
if (checkResult.isWorseThan(Quality::Good)) {
msg->AddText(checkResult.getFlags()[0].second.c_str());
}
int color = kWhite;
if (checkResult == Quality::Good) {
color = kGreen + 1;
msg->AddText(">> Quality::Good <<");
} else if (checkResult == Quality::Medium) {
color = kOrange - 1;
msg->AddText(">> Quality::Medium <<");
} else if (checkResult == Quality::Bad) {
color = kRed;
msg->AddText(">> Quality::Bad <<");
}
msg->SetFillColor(color);
}
}
} // namespace o2::quality_control_modules::fv0