Skip to content

Commit cb849d1

Browse files
committed
TRD raw data checks added
1 parent fcbef09 commit cb849d1

File tree

5 files changed

+349
-17
lines changed

5 files changed

+349
-17
lines changed

Modules/TRD/CMakeLists.txt

+30-17
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,21 @@
22

33
add_library(O2QcTRD)
44

5-
target_sources(O2QcTRD PRIVATE src/TrackletCountCheck.cxx src/PulsePositionCheck.cxx src/TrackingTask.cxx src/PulseHeightTrackMatch.cxx src/TrackletsCheck.cxx src/TrackletsTask.cxx src/PulseHeightCheck.cxx src/RawData.cxx src/DigitsTask.cxx
6-
src/TRDTrending.cxx src/TrendingTaskConfigTRD.cxx src/PulseHeightPostProcessing.cxx src/TRDHelpers.cxx)
5+
target_sources(O2QcTRD PRIVATE
6+
src/TrackletCountCheck.cxx
7+
src/PulsePositionCheck.cxx
8+
src/TrackingTask.cxx
9+
src/PulseHeightTrackMatch.cxx
10+
src/TrackletsCheck.cxx
11+
src/TrackletsTask.cxx
12+
src/PulseHeightCheck.cxx
13+
src/RawData.cxx
14+
src/RawDataCheck.cxx
15+
src/DigitsTask.cxx
16+
src/TRDTrending.cxx
17+
src/TrendingTaskConfigTRD.cxx
18+
src/PulseHeightPostProcessing.cxx
19+
src/TRDHelpers.cxx)
720

821
target_include_directories(
922
O2QcTRD
@@ -18,21 +31,21 @@ install(TARGETS O2QcTRD
1831
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1932
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2033

21-
add_root_dictionary(O2QcTRD
22-
HEADERS
23-
include/TRD/TrackletCountCheck.h
24-
include/TRD/PulsePositionCheck.h
25-
include/TRD/TrackingTask.h
26-
include/TRD/PulseHeightTrackMatch.h
27-
include/TRD/TrackletsCheck.h
28-
include/TRD/TrackletsTask.h
29-
include/TRD/TRDHelpers.h
30-
include/TRD/PulseHeightCheck.h
31-
include/TRD/RawData.h
32-
include/TRD/PulseHeightPostProcessing.h
33-
include/TRD/DigitsTask.h
34-
include/TRD/TRDTrending.h
35-
include/TRD/TrendingTaskConfigTRD.h
34+
add_root_dictionary(O2QcTRD HEADERS
35+
include/TRD/TrackletCountCheck.h
36+
include/TRD/PulsePositionCheck.h
37+
include/TRD/TrackingTask.h
38+
include/TRD/PulseHeightTrackMatch.h
39+
include/TRD/TrackletsCheck.h
40+
include/TRD/TrackletsTask.h
41+
include/TRD/TRDHelpers.h
42+
include/TRD/PulseHeightCheck.h
43+
include/TRD/RawData.h
44+
include/TRD/RawDataCheck.h
45+
include/TRD/PulseHeightPostProcessing.h
46+
include/TRD/DigitsTask.h
47+
include/TRD/TRDTrending.h
48+
include/TRD/TrendingTaskConfigTRD.h
3649
LINKDEF include/TRD/LinkDef.h)
3750

3851
# ---- Test(s) ----

Modules/TRD/include/TRD/LinkDef.h

+2
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@
1616
#pragma link C++ class o2::quality_control_modules::trd::TrackingTask + ;
1717
#pragma link C++ class o2::quality_control_modules::trd::PulsePositionCheck + ;
1818
#pragma link C++ class o2::quality_control_modules::trd::TrackletCountCheck + ;
19+
#pragma link C++ class o2::quality_control_modules::trd::RawDataCheckStats + ;
20+
#pragma link C++ class o2::quality_control_modules::trd::RawDataCheckSizes + ;
1921
#endif
+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
///
13+
/// \file RawDataCheck.h
14+
/// \author Ole Schmidt
15+
///
16+
17+
#ifndef QC_TRD_RAWDATA_CHECK_H
18+
#define QC_TRD_RAWDATA_CHECK_H
19+
20+
// Quality Control
21+
#include "QualityControl/CheckInterface.h"
22+
23+
namespace o2::quality_control_modules::trd
24+
{
25+
26+
/// \brief TRD raw data checks
27+
///
28+
29+
class RawDataCheckStats : public o2::quality_control::checker::CheckInterface
30+
{
31+
public:
32+
/// Default constructor
33+
RawDataCheckStats() = default;
34+
/// Destructor
35+
~RawDataCheckStats() override = default;
36+
37+
// Override interface
38+
void configure() override;
39+
Quality check(std::map<std::string, std::shared_ptr<MonitorObject>>* moMap) override;
40+
void beautify(std::shared_ptr<MonitorObject> mo, Quality checkResult = Quality::Null) override;
41+
std::string getAcceptedType() override;
42+
void reset() override;
43+
void startOfActivity(const Activity& activity) override;
44+
void endOfActivity(const Activity& activity) override;
45+
46+
private:
47+
std::shared_ptr<Activity> mActivity;
48+
float mCalTriggerRate;
49+
float mReadoutRate;
50+
float mMaxReadoutRate;
51+
float mMinCalTriggerRate;
52+
53+
ClassDefOverride(RawDataCheckStats, 1);
54+
};
55+
56+
class RawDataCheckSizes : public o2::quality_control::checker::CheckInterface
57+
{
58+
public:
59+
/// Default constructor
60+
RawDataCheckSizes() = default;
61+
/// Destructor
62+
~RawDataCheckSizes() override = default;
63+
64+
// Override interface
65+
void configure() override;
66+
Quality check(std::map<std::string, std::shared_ptr<MonitorObject>>* moMap) override;
67+
void beautify(std::shared_ptr<MonitorObject> mo, Quality checkResult = Quality::Null) override;
68+
std::string getAcceptedType() override;
69+
void reset() override;
70+
void startOfActivity(const Activity& activity) override;
71+
void endOfActivity(const Activity& activity) override;
72+
73+
private:
74+
std::shared_ptr<Activity> mActivity;
75+
float mMeanDataSize;
76+
float mStdDevDataSize;
77+
float mWarningThreshold;
78+
float mErrorThreshold;
79+
80+
ClassDefOverride(RawDataCheckSizes, 1);
81+
};
82+
83+
} // namespace o2::quality_control_modules::trd
84+
85+
#endif // QC_TRD_RAWDATA_CHECK_H

Modules/TRD/src/RawData.cxx

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ void RawData::startOfActivity(const Activity& activity)
194194
void RawData::startOfCycle()
195195
{
196196
ILOG(Debug, Devel) << "startOfCycle" << ENDM;
197+
mStats->Reset();
197198
}
198199

199200
void RawData::monitorData(o2::framework::ProcessingContext& ctx)

Modules/TRD/src/RawDataCheck.cxx

+231
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
///
13+
/// \file RawDataCheck.cxx
14+
/// \author Ole Schmidt
15+
16+
// C++
17+
#include <string>
18+
#include <fmt/core.h>
19+
// Fair
20+
#include <fairlogger/Logger.h>
21+
// ROOT
22+
#include <TH1.h>
23+
#include <TH2.h>
24+
#include <TLatex.h>
25+
#include <TList.h>
26+
#include <TPaveText.h>
27+
#include <TBox.h>
28+
#include <TPad.h>
29+
#include <TCanvas.h>
30+
#include <TMath.h>
31+
32+
// O2
33+
#include <DataFormatsQualityControl/FlagReasons.h>
34+
#include <CommonConstants/LHCConstants.h>
35+
#include <DataFormatsParameters/GRPECSObject.h>
36+
#include <CCDB/BasicCCDBManager.h>
37+
38+
// Quality Control
39+
#include "TRD/RawDataCheck.h"
40+
#include "QualityControl/MonitorObject.h"
41+
#include "QualityControl/Quality.h"
42+
#include "QualityControl/QcInfoLogger.h"
43+
#include "QualityControl/UserCodeInterface.h"
44+
45+
using namespace std;
46+
using namespace o2::quality_control;
47+
48+
namespace o2::quality_control_modules::trd
49+
{
50+
51+
void RawDataCheckStats::configure() {}
52+
53+
Quality RawDataCheckStats::check(std::map<std::string, std::shared_ptr<MonitorObject>>* moMap)
54+
{
55+
Quality result = Quality::Null;
56+
int runNumber = mActivity->mId;
57+
auto& ccdbmgr = o2::ccdb::BasicCCDBManager::instance();
58+
auto runDuration = ccdbmgr.getRunDuration(runNumber, false);
59+
map<string, string> metaData;
60+
metaData.emplace(std::pair<std::string, std::string>("runNumber", to_string(runNumber)));
61+
auto calib = UserCodeInterface::retrieveConditionAny<o2::parameters::GRPECSObject>("GLO/Config/GRPECS", metaData, runDuration.first);
62+
for (auto& [moName, mo] : *moMap) {
63+
(void)moName;
64+
if (mo->getName() == "stats") {
65+
auto* h = dynamic_cast<TH1F*>(mo->getObject());
66+
result.set(Quality::Good);
67+
if (h->GetBinContent(1) < 1 || h->GetBinContent(2) < 1) {
68+
result.set(Quality::Bad); // no readout triggers or histogram is completely empty
69+
} else {
70+
mReadoutRate = h->GetBinContent(2) / h->GetBinContent(1); // number of triggers per TF
71+
mReadoutRate *= 1. / (calib->getNHBFPerTF() * o2::constants::lhc::LHCOrbitMUS * 1e-6);
72+
mCalTriggerRate = h->GetBinContent(3) / h->GetBinContent(2);
73+
}
74+
if (mReadoutRate > mMaxReadoutRate) {
75+
result.set(Quality::Bad); // too high rate (should be triggered only for COSMICS run) TOF noisy?
76+
}
77+
if (mCalTriggerRate < mMinCalTriggerRate) {
78+
result.set(Quality::Medium); // no calibration triggers configured?
79+
}
80+
result.addMetadata("readoutRate", to_string(mReadoutRate));
81+
result.addMetadata("calTriggerRate", to_string(mCalTriggerRate));
82+
}
83+
}
84+
return result;
85+
}
86+
87+
void RawDataCheckStats::beautify(std::shared_ptr<MonitorObject> mo, Quality checkResult)
88+
{
89+
90+
if (mo->getName() == "stats") {
91+
auto* h = dynamic_cast<TH1F*>(mo->getObject());
92+
if (h->GetMaximum() < 1) {
93+
return;
94+
}
95+
auto msg = new TPaveText(0.5, h->GetMaximum() / 1e2, 2.5, h->GetMaximum());
96+
TText* txtPtr = nullptr;
97+
txtPtr = msg->AddText(Form("Readout rate: %.3f kHz", mReadoutRate / 1000.));
98+
txtPtr->SetTextAlign(12);
99+
txtPtr = msg->AddText(Form("Calibration trigger rate: %.4f", mCalTriggerRate));
100+
txtPtr->SetTextAlign(12);
101+
static_cast<TText*>(msg->GetListOfLines()->Last())->SetTextAlign(12);
102+
h->GetListOfFunctions()->Add(msg);
103+
if (checkResult == Quality::Good) {
104+
h->SetFillColor(kGreen);
105+
msg->SetFillColor(kGreen);
106+
} else if (checkResult == Quality::Bad) {
107+
ILOG(Debug, Devel) << "Quality::Bad, setting to red" << ENDM;
108+
h->SetFillColor(kRed);
109+
msg->SetFillColor(kRed);
110+
} else if (checkResult == Quality::Medium) {
111+
ILOG(Debug, Devel) << "Quality::medium, setting to orange" << ENDM;
112+
h->SetFillColor(kOrange);
113+
msg->SetFillColor(kOrange);
114+
}
115+
h->SetLineColor(kBlack);
116+
}
117+
}
118+
119+
std::string RawDataCheckStats::getAcceptedType()
120+
{
121+
return "TH1";
122+
}
123+
124+
void RawDataCheckStats::reset()
125+
{
126+
ILOG(Debug, Devel) << "RawDataCheckStats::reset" << ENDM;
127+
}
128+
129+
void RawDataCheckStats::startOfActivity(const Activity& activity)
130+
{
131+
ILOG(Debug, Devel) << "RawDataCheckStats::start : " << activity.mId << ENDM;
132+
mActivity = make_shared<Activity>(activity);
133+
// we cannot move the parameter initialization to configure(), as there the activity is not yet initialized
134+
mMaxReadoutRate = std::stof(mCustomParameters.atOptional("maxReadoutRate", *mActivity).value_or("1e6"));
135+
mMinCalTriggerRate = std::stof(mCustomParameters.atOptional("minCalTriggerRate", *mActivity).value_or("1e-5"));
136+
}
137+
138+
void RawDataCheckStats::endOfActivity(const Activity& activity)
139+
{
140+
ILOG(Debug, Devel) << "RawDataCheckStats::end : " << activity.mId << ENDM;
141+
}
142+
143+
void RawDataCheckSizes::configure() {}
144+
145+
Quality RawDataCheckSizes::check(std::map<std::string, std::shared_ptr<MonitorObject>>* moMap)
146+
{
147+
Quality result = Quality::Null;
148+
149+
for (auto& [moName, mo] : *moMap) {
150+
(void)moName;
151+
if (mo->getName() == "datavolumepersector") {
152+
auto* h = dynamic_cast<TH2F*>(mo->getObject());
153+
result.set(Quality::Good);
154+
TObjArray fits;
155+
h->FitSlicesY(nullptr, 1, 18, 0, "QNR", &fits);
156+
auto hMean = (TH1F*)fits[1];
157+
double sum = 0, sum2 = 0, n = 0;
158+
for (int iBin = 1; iBin <= 18; ++iBin) {
159+
sum += hMean->GetBinContent(iBin);
160+
sum2 += hMean->GetBinContent(iBin) * hMean->GetBinContent(iBin);
161+
++n;
162+
mMeanDataSize = sum / n;
163+
mStdDevDataSize = sum2 / n - TMath::Power(sum / n, 2);
164+
}
165+
mStdDevDataSize = TMath::Sqrt(mStdDevDataSize);
166+
for (int iBin = 1; iBin <= 18; ++iBin) {
167+
if (TMath::Abs(hMean->GetBinContent(iBin) - mMeanDataSize) > mWarningThreshold * mStdDevDataSize) {
168+
ILOG(Debug, Support) << fmt::format("Found outlier in sector {} with mean value of {}", iBin - 1, hMean->GetBinContent(iBin)) << ENDM;
169+
result.set(Quality::Medium);
170+
}
171+
if (TMath::Abs(hMean->GetBinContent(iBin) - mMeanDataSize) > mErrorThreshold * mStdDevDataSize) {
172+
ILOG(Debug, Support) << fmt::format("Found strong outlier in sector {} with mean value of {}", iBin - 1, hMean->GetBinContent(iBin)) << ENDM;
173+
result.set(Quality::Bad);
174+
}
175+
}
176+
ILOG(Debug, Support) << fmt::format("Data size plot: Mean({}), StdDev({}).", mMeanDataSize, mStdDevDataSize) << ENDM;
177+
result.addMetadata("dataSizeMean", to_string(mMeanDataSize));
178+
result.addMetadata("dataSizeStdDev", to_string(mStdDevDataSize));
179+
}
180+
}
181+
return result;
182+
}
183+
184+
void RawDataCheckSizes::beautify(std::shared_ptr<MonitorObject> mo, Quality checkResult)
185+
{
186+
if (mo->getName() == "datavolumepersector") {
187+
ILOG(Debug, Support) << "Found the meta data \"foo\": " << checkResult.getMetadata("foo", "ramtam") << ENDM;
188+
auto* h = dynamic_cast<TH2F*>(mo->getObject());
189+
auto msg = new TPaveText(4, 3000, 10, 3800);
190+
msg->AddText(Form("Average volume per sector: %.2f Bytes/TF", mMeanDataSize));
191+
static_cast<TText*>(msg->GetListOfLines()->Last())->SetTextAlign(12);
192+
msg->AddText(Form("sigma: %.3f", mStdDevDataSize));
193+
static_cast<TText*>(msg->GetListOfLines()->Last())->SetTextAlign(12);
194+
h->GetListOfFunctions()->Add(msg);
195+
if (checkResult == Quality::Good) {
196+
msg->SetFillColor(kGreen);
197+
} else if (checkResult == Quality::Bad) {
198+
ILOG(Debug, Devel) << "Quality::Bad, setting to red" << ENDM;
199+
msg->SetFillColor(kRed);
200+
} else if (checkResult == Quality::Medium) {
201+
ILOG(Debug, Devel) << "Quality::medium, setting to orange" << ENDM;
202+
msg->SetFillColor(kOrange);
203+
}
204+
}
205+
}
206+
207+
std::string RawDataCheckSizes::getAcceptedType()
208+
{
209+
return "TH2";
210+
}
211+
212+
void RawDataCheckSizes::reset()
213+
{
214+
ILOG(Debug, Devel) << "RawDataCheckSizes::reset" << ENDM;
215+
}
216+
217+
void RawDataCheckSizes::startOfActivity(const Activity& activity)
218+
{
219+
ILOG(Debug, Devel) << "RawDataCheckSizes::start : " << activity.mId << ENDM;
220+
mActivity = make_shared<Activity>(activity);
221+
// we cannot move the parameter initialization to configure(), as there the activity is not yet initialized
222+
mWarningThreshold = std::stof(mCustomParameters.atOptional("warningThreshold", *mActivity).value_or("3"));
223+
mErrorThreshold = std::stof(mCustomParameters.atOptional("errorThreshold", *mActivity).value_or("5"));
224+
}
225+
226+
void RawDataCheckSizes::endOfActivity(const Activity& activity)
227+
{
228+
ILOG(Debug, Devel) << "RawDataCheckSizes::end : " << activity.mId << ENDM;
229+
}
230+
231+
} // namespace o2::quality_control_modules::trd

0 commit comments

Comments
 (0)