Skip to content

Commit a319bf2

Browse files
committed
add treatment of TOF DRM Errors
1 parent d569998 commit a319bf2

File tree

9 files changed

+222
-13
lines changed

9 files changed

+222
-13
lines changed

DataFormats/Detectors/TOF/include/DataFormatsTOF/Diagnostic.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ class Diagnostic
4444
uint32_t fillEmptyTOF(uint32_t frequency = 1) { return fill(1, frequency); }
4545
static ULong64_t getEmptyCrateKey(int crate);
4646
static ULong64_t getNoisyChannelKey(int channel);
47+
static ULong64_t getDRMKey(int crate) { return 1000000 + crate * 1000; }
48+
static ULong64_t getDRMerrorKey(int crate, int error) { return getDRMKey(crate) + error; }
49+
uint32_t getFrequencyDRM(int crate) const { return getFrequency(getDRMKey(crate)); }
50+
uint32_t getFrequencyDRMerror(int crate, int error) const { return getFrequency(getDRMerrorKey(crate, error)); }
51+
uint32_t fillDRM(int crate, uint32_t frequency) { return fill(getDRMKey(crate), frequency); }
52+
uint32_t fillDRMerror(int crate, int error, uint32_t frequency) { return fill(getDRMerrorKey(crate, error), frequency); }
53+
4754
static ULong64_t getTRMKey(int crate, int trm);
4855
void print(bool longFormat = false) const;
4956
void clear() { mVector.clear(); }

Detectors/TOF/base/include/TOFBase/CalibTOFapi.h

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "DataFormatsTOF/Diagnostic.h"
2525
#include "DataFormatsTOF/TOFFEElightInfo.h"
2626

27+
class TH2F;
28+
2729
namespace o2
2830
{
2931
namespace tof
@@ -38,10 +40,12 @@ class CalibTOFapi
3840
using CcdbApi = o2::ccdb::CcdbApi;
3941

4042
public:
43+
static o2::tof::Diagnostic doDRMerrCalibFromQCHisto(const TH2F* histo, const char* file_output_name);
44+
4145
void resetDia();
4246
CalibTOFapi() = default;
4347
CalibTOFapi(const std::string url);
44-
CalibTOFapi(long timestamp, o2::dataformats::CalibLHCphaseTOF* phase, o2::dataformats::CalibTimeSlewingParamTOF* slew, Diagnostic* dia = nullptr) : mTimeStamp(timestamp), mLHCphase(phase), mSlewParam(slew), mDiaFreq(dia) {}
48+
CalibTOFapi(long timestamp, o2::dataformats::CalibLHCphaseTOF* phase, o2::dataformats::CalibTimeSlewingParamTOF* slew, Diagnostic* dia = nullptr, Diagnostic* diaDRM = nullptr) : mTimeStamp(timestamp), mLHCphase(phase), mSlewParam(slew), mDiaFreq(dia), mDiaDRMFreq(diaDRM) {}
4549
~CalibTOFapi()
4650
{
4751
if (mLHCphase) {
@@ -53,6 +57,9 @@ class CalibTOFapi
5357
if (mDiaFreq) {
5458
// delete mDiaFreq;
5559
}
60+
if (mDiaDRMFreq) {
61+
// delete mDiaDRMFreq;
62+
}
5663
}
5764

5865
void setTimeStamp(long t)
@@ -69,6 +76,8 @@ class CalibTOFapi
6976
void readTimeSlewingParamFromFile(const char* filename);
7077
void readDiagnosticFrequencies();
7178
void loadDiagnosticFrequencies();
79+
void readDiagnosticDRMFrequencies();
80+
void loadDiagnosticDRMFrequencies();
7281
void readActiveMap();
7382
void loadActiveMap(TOFFEElightInfo* fee);
7483
void writeLHCphase(LhcPhase* phase, std::map<std::string, std::string> metadataLHCphase, uint64_t minTimeSTamp, uint64_t maxTimeStamp);
@@ -89,6 +98,8 @@ class CalibTOFapi
8998
void setLhcPhase(LhcPhase* obj) { mLHCphase = obj; }
9099
Diagnostic* getDiagnostic() { return mDiaFreq; }
91100
void setDiagnostic(Diagnostic* obj) { mDiaFreq = obj; }
101+
Diagnostic* getDiagnosticDRM() { return mDiaDRMFreq; }
102+
void setDiagnosticDRM(Diagnostic* obj) { mDiaDRMFreq = obj; }
92103

93104
int getNoisyThreshold() const { return mNoisyThreshold; }
94105
void setNoisyThreshold(int val) { mNoisyThreshold = val; }
@@ -103,11 +114,15 @@ class CalibTOFapi
103114
bool isChannelError(int channel) const;
104115
bool checkTRMPolicy(int mask) const;
105116

117+
void setDRMCriticalErrorMask(uint32_t val) { mDRMCriticalErrorMask = val; }
118+
uint32_t getDRMCriticalErrorMask() const { return mDRMCriticalErrorMask; }
119+
106120
private:
107-
long mTimeStamp; ///< timeStamp for queries
108-
LhcPhase* mLHCphase = nullptr; ///< object for LHC phase
109-
SlewParam* mSlewParam = nullptr; ///< object for timeslewing (containing info also for offset and problematic)
110-
Diagnostic* mDiaFreq = nullptr; ///< object for Diagnostic Frequency
121+
long mTimeStamp; ///< timeStamp for queries
122+
LhcPhase* mLHCphase = nullptr; ///< object for LHC phase
123+
SlewParam* mSlewParam = nullptr; ///< object for timeslewing (containing info also for offset and problematic)
124+
Diagnostic* mDiaFreq = nullptr; ///< object for Diagnostic Frequency
125+
Diagnostic* mDiaDRMFreq = nullptr; ///< object for Diagnostic Frequency
111126

112127
// info from diagnostic
113128
int mNoisyThreshold = 1; ///< threshold to be noisy
@@ -116,13 +131,15 @@ class CalibTOFapi
116131
std::vector<std::pair<int, float>> mNoisy; ///< probTRMerror
117132
std::vector<std::pair<int, float>> mTRMerrorProb; ///< probTRMerror
118133
std::vector<int> mTRMmask; ///< mask error for TRM
134+
float mErrorInDRM[72] = {}; ///< probability of DRM error
135+
uint32_t mDRMCriticalErrorMask = 0; ///< bit mask for critical DRM errors (e.g. Orbit Mismatch -> 1 << 7, see DataFormats/Detectors/TOF/include/DataFormatsTOF/CompressedDataFormat.h)
119136

120137
bool mIsErrorCh[Geo::NCHANNELS] = {}; ///< channels in error (TRM)
121138
std::vector<int> mFillErrChannel; ///< last error channels filled
122139
bool mIsOffCh[Geo::NCHANNELS] = {}; ///< channels in error (TRM)
123140
bool mIsNoisy[Geo::NCHANNELS] = {}; ///< noisy channels
124141

125-
ClassDefNV(CalibTOFapi, 1);
142+
ClassDefNV(CalibTOFapi, 2);
126143
};
127144
} // namespace tof
128145
} // namespace o2

Detectors/TOF/base/src/CalibTOFapi.cxx

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,40 @@
1111

1212
#include "TOFBase/CalibTOFapi.h"
1313
#include <fairlogger/Logger.h> // for LOG
14+
#include <TH2F.h>
1415

1516
using namespace o2::tof;
1617

1718
ClassImp(o2::tof::CalibTOFapi);
1819

20+
o2::tof::Diagnostic CalibTOFapi::doDRMerrCalibFromQCHisto(const TH2F* histo, const char* file_output_name)
21+
{
22+
// this is a method which translate the QC output in qc/TOF/MO/TaskRaw/DRMCounter (TH2F) into a Diagnotic object for DRM (patter(crate, error), frequency)
23+
// note that, differently from TRM errors, DRM ones are not stored in CTF by design (since very rare, as expected). Such an info is available only at the level of raw sync QC
24+
o2::tof::Diagnostic drmDia;
25+
26+
for (int j = 1; j <= 72; j++) {
27+
drmDia.fillDRM(j - 1, histo->GetBinContent(1, j));
28+
for (int i = 2; i <= histo->GetXaxis()->GetNbins(); i++) {
29+
if (histo->GetBinContent(1, j)) {
30+
if (histo->GetBinContent(i, j) > 0) {
31+
drmDia.fillDRMerror(j - 1, i - 1, histo->GetBinContent(i, j));
32+
}
33+
}
34+
}
35+
}
36+
37+
TFile* fo = new TFile(file_output_name, "RECREATE");
38+
fo->WriteObjectAny(&drmDia, drmDia.Class_Name(), "ccdb_object");
39+
fo->Close();
40+
LOG(info) << "DRM error ccdb object created in " << file_output_name << " with this content";
41+
drmDia.print(true);
42+
43+
return drmDia;
44+
}
45+
46+
//______________________________________________________________________
47+
1948
void CalibTOFapi::resetDia()
2049
{
2150
memset(mEmptyCrateProb, 0., Geo::kNCrate * 4);
@@ -116,11 +145,23 @@ void CalibTOFapi::readDiagnosticFrequencies()
116145
{
117146
auto& mgr = CcdbManager::instance();
118147
long timems = long(mTimeStamp) * 1000;
119-
LOG(info) << "TOF get Diagnostics with timestamp (ms) = " << timems;
148+
LOG(info) << "TOF get TRM Diagnostics with timestamp (ms) = " << timems;
120149
mDiaFreq = mgr.getForTimeStamp<Diagnostic>("TOF/Calib/Diagnostic", timems);
121150

122151
loadDiagnosticFrequencies();
123152
}
153+
154+
//______________________________________________________________________
155+
156+
void CalibTOFapi::readDiagnosticDRMFrequencies()
157+
{
158+
auto& mgr = CcdbManager::instance();
159+
long timems = long(mTimeStamp) * 1000;
160+
LOG(info) << "TOF get DRM Diagnostics with timestamp (ms) = " << timems;
161+
mDiaFreq = mgr.getForTimeStamp<Diagnostic>("TOF/Calib/TRMerrors", timems);
162+
163+
loadDiagnosticDRMFrequencies();
164+
}
124165
//______________________________________________________________________
125166

126167
void CalibTOFapi::loadDiagnosticFrequencies()
@@ -210,6 +251,36 @@ void CalibTOFapi::loadDiagnosticFrequencies()
210251

211252
//______________________________________________________________________
212253

254+
void CalibTOFapi::loadDiagnosticDRMFrequencies()
255+
{
256+
mDiaDRMFreq->print();
257+
258+
for (int ic = 0; ic < 72; ic++) { // loop over crates
259+
float DRMcounters = mDiaDRMFreq->getFrequencyDRM(ic);
260+
261+
if (DRMcounters < 1) {
262+
mErrorInDRM[ic] = 0.;
263+
continue;
264+
}
265+
266+
float probGood = 1;
267+
268+
for (int ie = 0; ie < 28; ie++) { // loop over error types
269+
uint32_t bitError = 1 << ie;
270+
if (bitError & mDRMCriticalErrorMask) { // if error has to be masked
271+
float frequency = mDiaDRMFreq->getFrequencyDRMerror(ic, ie) * 1. / mErrorInDRM[ic]; // error frequency
272+
if (frequency > 1) {
273+
frequency = 1.;
274+
}
275+
probGood *= (1 - frequency); // frequency of no error assuming all types are independent
276+
}
277+
}
278+
mErrorInDRM[ic] = 1 - probGood; // probability of at least one error to be masked
279+
}
280+
}
281+
282+
//______________________________________________________________________
283+
213284
void CalibTOFapi::writeLHCphase(LhcPhase* phase, std::map<std::string, std::string> metadataLHCphase, uint64_t minTimeStamp, uint64_t maxTimeStamp)
214285
{
215286

Detectors/TOF/prototyping/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ o2_add_test_root_macro(findLabels.C
3232
O2::TOFBase
3333
LABELS tof)
3434

35+
o2_add_test_root_macro(makeDRMobj_tof.C
36+
PUBLIC_LINK_LIBRARIES O2::DataFormatsTOF
37+
O2::TOFBase
38+
LABELS tof)
39+
40+
o2_add_test_root_macro(checkDRMobj_tof.C
41+
PUBLIC_LINK_LIBRARIES O2::DataFormatsTOF
42+
O2::TOFBase
43+
LABELS tof)
44+
3545
o2_add_test_root_macro(findTOFclusterFromLabel.C
3646
PUBLIC_LINK_LIBRARIES O2::DataFormatsTOF
3747
O2::SimulationDataFormat
@@ -59,3 +69,8 @@ o2_add_test_root_macro(macroEvTime.C
5969
PUBLIC_LINK_LIBRARIES O2::TOFBase
6070
O2::TOFReconstruction
6171
LABELS tof)
72+
73+
install(
74+
FILES makeDRMobj_tof.C
75+
checkDRMobj_tof.C
76+
DESTINATION share/macro/)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
#if !defined(__CLING__) || defined(__ROOTCLING__)
13+
#include "TFile.h"
14+
#include "TH2F.h"
15+
#include "TOFBase/CalibTOFapi.h"
16+
#endif
17+
18+
void checkDRMobj_tof(const char* fname = "ccdb.root")
19+
{
20+
TFile* f = new TFile(fname);
21+
22+
TH2F* hErrors = new TH2F("hDRMerrors", ";error code; frequency", 30, 0, 30, 72, 0, 72);
23+
24+
o2::tof::Diagnostic* drmDia = (o2::tof::Diagnostic*)f->Get("ccdb_object");
25+
26+
for (int j = 1; j <= 72; j++) {
27+
uint32_t patternRDH = o2::tof::Diagnostic::getDRMKey(j - 1);
28+
for (int i = 1; i <= hErrors->GetXaxis()->GetNbins(); i++) {
29+
uint32_t pattern = o2::tof::Diagnostic::getDRMerrorKey(j - 1, i - 1);
30+
if (drmDia->getFrequency(patternRDH)) {
31+
hErrors->SetBinContent(i, j, drmDia->getFrequency(pattern) * 1. / drmDia->getFrequency(patternRDH));
32+
}
33+
}
34+
}
35+
36+
TCanvas* c = new TCanvas();
37+
c->cd(1);
38+
hErrors->Draw("colz");
39+
40+
drmDia->print(true);
41+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
#if !defined(__CLING__) || defined(__ROOTCLING__)
13+
#include "TFile.h"
14+
#include "TH2F.h"
15+
#include "TOFBase/CalibTOFapi.h"
16+
#endif
17+
18+
void makeDRMobj_tof(const char* inputfile = "TObject_1764607157510.root", bool dummy = false)
19+
{
20+
if (dummy) {
21+
o2::tof::Diagnostic drmDia;
22+
for (int j = 1; j <= 72; j++) {
23+
drmDia.fill(o2::tof::Diagnostic::getDRMKey(j - 1));
24+
}
25+
26+
TFile* fo = new TFile("ccdb.root", "RECREATE");
27+
fo->WriteObjectAny(&drmDia, drmDia.Class_Name(), "ccdb_object");
28+
fo->Close();
29+
30+
return;
31+
}
32+
33+
TFile* f = new TFile(inputfile);
34+
TH2F* h = (TH2F*)f->Get("ccdb_object");
35+
36+
o2::tof::Diagnostic drmDia;
37+
38+
drmDia = o2::tof::CalibTOFapi::doDRMerrCalibFromQCHisto(h, "ccdb.root");
39+
}

Steer/DigitizerWorkflow/src/SimpleDigitizerWorkflow.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
202202
// option to use/not use CCDB for TOF
203203
workflowOptions.push_back(ConfigParamSpec{"use-ccdb-tof", o2::framework::VariantType::Bool, false, {"enable access to ccdb tof calibration objects"}});
204204
workflowOptions.push_back(ConfigParamSpec{"ccdb-tof-sa", o2::framework::VariantType::Bool, false, {"enable access to ccdb tof calibration objects via CCDBManager (obsolete remap to use-ccdb-tof)"}});
205+
workflowOptions.push_back(ConfigParamSpec{"tof-drm-bitmask", o2::framework::VariantType::Int, 128, {"bit mask of DRM critical errors"}}); // 128 = orbit mismatch
205206

206207
// option to use/not use CCDB for FT0
207208
workflowOptions.push_back(ConfigParamSpec{"use-ccdb-ft0", o2::framework::VariantType::Bool, false, {"enable access to ccdb ft0 calibration objects"}});
@@ -677,10 +678,11 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
677678
auto ccdb_url_tof = o2::base::NameConf::getCCDBServer();
678679
auto timestamp = o2::raw::HBFUtils::Instance().startTime / 1000;
679680
detList.emplace_back(o2::detectors::DetID::TOF);
681+
auto maskDRM = (uint32_t)configcontext.options().get<int>("tof-drm-bitmask");
680682
// connect the TOF digitization
681683
// printf("TOF Setting: use-ccdb = %d ---- ccdb url=%s ---- timestamp=%ld\n", useCCDB, ccdb_url_tof.c_str(), timestamp);
682684

683-
digitizerSpecs.emplace_back(o2::tof::getTOFDigitizerSpec(fanoutsize++, useCCDB, mctruth, ccdb_url_tof.c_str(), timestamp));
685+
digitizerSpecs.emplace_back(o2::tof::getTOFDigitizerSpec(fanoutsize++, useCCDB, mctruth, ccdb_url_tof.c_str(), timestamp, maskDRM));
684686
// add TOF digit writer
685687
writerSpecs.emplace_back(o2::tof::getTOFDigitWriterSpec(mctruth));
686688
}

0 commit comments

Comments
 (0)