Skip to content

Commit 7c60d51

Browse files
sweyh99Sierra Weyhmiller
andauthored
[EMCAL-529] Added checker for Number of Patches per FastOR Trigger histo (#2258)
Check for noisy FastORs and message in the quality object and infologger which TRUs are noisy Co-authored-by: Sierra Weyhmiller <sierra.lisa.weyhmiller@cern.ch>
1 parent 702f9df commit 7c60d51

4 files changed

Lines changed: 229 additions & 3 deletions

File tree

Modules/EMCAL/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
add_library(O2QcEMCAL)
44

5-
target_sources(O2QcEMCAL PRIVATE src/TriggerTask.cxx src/PedestalTask.cxx src/BCTask.cxx src/RawErrorCheck.cxx src/RawTask.cxx src/RawCheck.cxx src/CellTask.cxx src/CellCheck.cxx src/DigitsQcTask.cxx src/DigitCheck.cxx src/OccupancyReductor.cxx src/ClusterTask.cxx src/RawErrorTask.cxx src/CalibMonitoringTask.cxx src/SupermoduleProjectorTask.cxx src/BadChannelMapReductor.cxx src/TimeCalibParamReductor.cxx src/SupermoduleProjectionReductor.cxx src/SubdetectorProjectionReductor.cxx src/BCVisualization.cxx src/CalibCheck.cxx)
5+
target_sources(O2QcEMCAL PRIVATE src/TriggerTask.cxx src/PedestalTask.cxx src/BCTask.cxx src/RawErrorCheck.cxx src/RawTask.cxx src/RawCheck.cxx src/CellTask.cxx src/CellCheck.cxx src/DigitsQcTask.cxx src/DigitCheck.cxx src/OccupancyReductor.cxx src/ClusterTask.cxx src/RawErrorTask.cxx src/CalibMonitoringTask.cxx src/SupermoduleProjectorTask.cxx src/BadChannelMapReductor.cxx src/TimeCalibParamReductor.cxx src/SupermoduleProjectionReductor.cxx src/SubdetectorProjectionReductor.cxx src/BCVisualization.cxx src/CalibCheck.cxx src/NumPatchesPerFastORCheck.cxx)
66

77
target_include_directories(
88
O2QcEMCAL
99
PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
1010
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src
1111
)
1212

13-
target_link_libraries(O2QcEMCAL PUBLIC O2QualityControl O2::DetectorsBase O2::EMCALBase O2::EMCALReconstruction O2::CCDB O2::EMCALCalib O2::DataFormatsCTP)
13+
target_link_libraries(O2QcEMCAL PUBLIC O2QualityControl O2::DetectorsBase O2::EMCALBase O2::EMCALReconstruction O2::CCDB O2::EMCALCalib O2::DataFormatsCTP ROOT::Spectrum)
1414

1515
add_root_dictionary(O2QcEMCAL
1616
HEADERS include/EMCAL/DigitsQcTask.h
@@ -34,6 +34,7 @@ add_root_dictionary(O2QcEMCAL
3434
include/EMCAL/PedestalTask.h
3535
include/EMCAL/TriggerTask.h
3636
include/EMCAL/CalibCheck.h
37+
include/EMCAL/NumPatchesPerFastORCheck.h
3738
LINKDEF include/EMCAL/LinkDef.h)
3839

3940
install(TARGETS O2QcEMCAL

Modules/EMCAL/include/EMCAL/LinkDef.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@
4343

4444
#pragma link C++ class o2::quality_control_modules::emcal::CalibCheck + ;
4545
#pragma link C++ class o2::quality_control_modules::emcal::TriggerTask + ;
46+
#pragma link C++ class o2::quality_control_modules::emcal::NumPatchesPerFastORCheck + ;
4647

47-
#endif
48+
#endif
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 NumPatchesPerFastORCheck.h
14+
/// \author Sierra Cantway
15+
///
16+
17+
#ifndef QC_MODULE_EMCAL_EMCALNUMPATCHESPERFASTORCHECK_H
18+
#define QC_MODULE_EMCAL_EMCALNUMPATCHESPERFASTORCHECK_H
19+
20+
#include "QualityControl/CheckInterface.h"
21+
#include "EMCALBase/TriggerMappingV2.h"
22+
#include "EMCALBase/Geometry.h"
23+
24+
namespace o2::quality_control_modules::emcal
25+
{
26+
27+
/// \brief Check whether a plot is good or not.
28+
///
29+
/// \author Sierra Cantway
30+
class NumPatchesPerFastORCheck : public o2::quality_control::checker::CheckInterface
31+
{
32+
public:
33+
/// Default constructor
34+
NumPatchesPerFastORCheck() = default;
35+
/// Destructor
36+
~NumPatchesPerFastORCheck() override = default;
37+
38+
// Override interface
39+
void configure() override;
40+
Quality check(std::map<std::string, std::shared_ptr<MonitorObject>>* moMap) override;
41+
void beautify(std::shared_ptr<MonitorObject> mo, Quality checkResult = Quality::Null) override;
42+
std::string getAcceptedType() override;
43+
44+
private:
45+
/************************************************
46+
* threshold cuts *
47+
************************************************/
48+
49+
float mBadThresholdNumPatchesPerFastOR = 4.; ///< Bad Threshold used in the Number of Patches Per FastOR check
50+
float mSigmaTSpectrum = 0.1; ///< TSpectrum parameter sigma
51+
float mThreshTSpectrum = 0.01; ///< TSpectrum parameter threshold
52+
53+
o2::emcal::Geometry* mGeometry = o2::emcal::Geometry::GetInstanceFromRunNumber(300000); ///< Geometry for mapping position between SM and full EMCAL
54+
std::unique_ptr<o2::emcal::TriggerMappingV2> mTriggerMapping = std::make_unique<o2::emcal::TriggerMappingV2>(mGeometry); ///!<! Trigger mapping
55+
std::stringstream mErrorMessage; ///< Message to send to log for all found noisy TRUs
56+
std::vector<std::pair<double, double>> mNoisyTRUPositions; ///< Positions of all found noisy TRUs
57+
58+
ClassDefOverride(NumPatchesPerFastORCheck, 1);
59+
};
60+
61+
} // namespace o2::quality_control_modules::emcal
62+
63+
#endif // QC_MODULE_EMCAL_EMCALNUMPATCHESPERFASTORCHECK_H
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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 NumPatchesPerFastORCheck.cxx
14+
/// \author Sierra Cantway
15+
///
16+
17+
#include "EMCAL/NumPatchesPerFastORCheck.h"
18+
#include "QualityControl/MonitorObject.h"
19+
#include "QualityControl/Quality.h"
20+
#include "QualityControl/QcInfoLogger.h"
21+
#include "EMCALBase/Geometry.h"
22+
#include <fairlogger/Logger.h>
23+
// ROOT
24+
#include <TH1.h>
25+
#include <TH2.h>
26+
#include <TPaveText.h>
27+
#include <TLatex.h>
28+
#include <TList.h>
29+
#include <TRobustEstimator.h>
30+
#include <TMath.h>
31+
#include <ROOT/TSeq.hxx>
32+
#include <TSpectrum.h>
33+
#include <iostream>
34+
#include <vector>
35+
#include <sstream>
36+
37+
using namespace std;
38+
39+
namespace o2::quality_control_modules::emcal
40+
{
41+
42+
void NumPatchesPerFastORCheck::configure()
43+
{
44+
// configure threshold-based checkers for bad quality
45+
auto nBadThresholdNumPatchesPerFastOR = mCustomParameters.find("BadThresholdNumPatchesPerFastOR");
46+
if (nBadThresholdNumPatchesPerFastOR != mCustomParameters.end()) {
47+
try {
48+
mBadThresholdNumPatchesPerFastOR = std::stof(nBadThresholdNumPatchesPerFastOR->second);
49+
} catch (std::exception& e) {
50+
ILOG(Error, Support) << fmt::format("Value {} not a float", nBadThresholdNumPatchesPerFastOR->second.data()) << ENDM;
51+
}
52+
}
53+
54+
// configure TSpectrum parameters
55+
auto nSigmaTSpectrum = mCustomParameters.find("TSpecSigma");
56+
if (nSigmaTSpectrum != mCustomParameters.end()) {
57+
try {
58+
mSigmaTSpectrum = std::stof(nSigmaTSpectrum->second);
59+
} catch (std::exception& e) {
60+
ILOG(Error, Support) << fmt::format("Value {} not a float", nSigmaTSpectrum->second.data()) << ENDM;
61+
}
62+
}
63+
64+
auto nThreshTSpectrum = mCustomParameters.find("TSpecThresh");
65+
if (nThreshTSpectrum != mCustomParameters.end()) {
66+
try {
67+
mThreshTSpectrum = std::stof(nThreshTSpectrum->second);
68+
} catch (std::exception& e) {
69+
ILOG(Error, Support) << fmt::format("Value {} not a float", nThreshTSpectrum->second.data()) << ENDM;
70+
}
71+
}
72+
}
73+
74+
Quality NumPatchesPerFastORCheck::check(std::map<std::string, std::shared_ptr<MonitorObject>>* moMap)
75+
{
76+
auto mo = moMap->begin()->second;
77+
Quality result = Quality::Good;
78+
mErrorMessage.str("");
79+
mNoisyTRUPositions.clear();
80+
81+
if (mo->getName() == "NumberOfPatchesWithFastOR") {
82+
auto* h = dynamic_cast<TH1*>(mo->getObject());
83+
if (h->GetEntries() == 0) {
84+
result = Quality::Medium;
85+
} else {
86+
std::vector<double> smcounts;
87+
for (auto ib : ROOT::TSeqI(0, h->GetXaxis()->GetNbins())) {
88+
auto countSM = h->GetBinContent(ib + 1);
89+
if (countSM > 0) {
90+
smcounts.emplace_back(countSM);
91+
}
92+
}
93+
if (!smcounts.size()) {
94+
result = Quality::Medium;
95+
} else {
96+
TRobustEstimator meanfinder;
97+
double mean, sigma;
98+
meanfinder.EvaluateUni(smcounts.size(), smcounts.data(), mean, sigma);
99+
100+
TSpectrum peakfinder;
101+
Int_t nfound = peakfinder.Search(h, mSigmaTSpectrum, "nobackground", mThreshTSpectrum); // Search for peaks //CHANGE - make config?
102+
Double_t* xpeaks = peakfinder.GetPositionX();
103+
Double_t* ypeaks = peakfinder.GetPositionY();
104+
std::sort(ypeaks, ypeaks + nfound, std::greater<double>()); // sort peaks in descending order to easy pick the y value of max peak
105+
double threshold = mBadThresholdNumPatchesPerFastOR * mean;
106+
107+
for (Int_t n_peak = 0; n_peak < nfound; n_peak++) {
108+
Int_t bin = h->GetXaxis()->FindBin(xpeaks[n_peak]);
109+
Double_t peak_val = h->GetBinContent(bin);
110+
111+
if (peak_val > threshold) {
112+
result = Quality::Bad;
113+
Double_t peak_pos = h->GetXaxis()->GetBinCenter(bin);
114+
auto [truID, fastorTRU] = mTriggerMapping->getTRUFromAbsFastORIndex(peak_pos);
115+
mErrorMessage << "TRU " << truID << " has a noisy FastOR at position " << fastorTRU << " in TRU." << std::endl;
116+
ILOG(Error, Support) << "TRU " << truID << " has a noisy FastOR at position " << fastorTRU << " in TRU." << ENDM;
117+
mNoisyTRUPositions.push_back(std::make_pair(truID, fastorTRU));
118+
}
119+
}
120+
}
121+
}
122+
}
123+
124+
return result;
125+
}
126+
127+
std::string NumPatchesPerFastORCheck::getAcceptedType() { return "TH1"; }
128+
129+
void NumPatchesPerFastORCheck::beautify(std::shared_ptr<MonitorObject> mo, Quality checkResult)
130+
{
131+
// To do - good message
132+
if (mo->getName() == "NumberOfPatchesWithFastOR") {
133+
auto* h = dynamic_cast<TH1*>(mo->getObject());
134+
if (checkResult == Quality::Bad) {
135+
TLatex* msg;
136+
if (!mErrorMessage.str().empty()) {
137+
ILOG(Error, Support) << mErrorMessage.str() << ENDM;
138+
msg = new TLatex(0.15, 0.84, "#color[2]{Error: Noisy TRU(s)}");
139+
msg->SetNDC();
140+
msg->SetTextSize(16);
141+
msg->SetTextFont(43);
142+
msg->SetTextColor(kRed);
143+
h->GetListOfFunctions()->Add(msg);
144+
msg->Draw();
145+
}
146+
for (int iErr = 0; iErr < mNoisyTRUPositions.size(); iErr++) {
147+
stringstream errorMessageIndiv;
148+
errorMessageIndiv << "Position " << mNoisyTRUPositions[iErr].second << " in TRU " << mNoisyTRUPositions[iErr].first << " is noisy." << std::endl;
149+
msg = new TLatex(0.15, 0.8 - iErr / 25., errorMessageIndiv.str().c_str());
150+
msg->SetNDC();
151+
msg->SetTextSize(16);
152+
msg->SetTextFont(43);
153+
msg->SetTextColor(kRed);
154+
h->GetListOfFunctions()->Add(msg);
155+
msg->Draw();
156+
ILOG(Error, Support) << errorMessageIndiv.str() << ENDM;
157+
}
158+
}
159+
}
160+
}
161+
} // namespace o2::quality_control_modules::emcal

0 commit comments

Comments
 (0)