Skip to content

Commit 6e9b57d

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

File tree

13 files changed

+343
-28
lines changed

13 files changed

+343
-28
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: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include "TOFBase/Geo.h"
2424
#include "DataFormatsTOF/Diagnostic.h"
2525
#include "DataFormatsTOF/TOFFEElightInfo.h"
26+
#include "DataFormatsTOF/CompressedDataFormat.h"
27+
28+
class TH2F;
2629

2730
namespace o2
2831
{
@@ -38,10 +41,12 @@ class CalibTOFapi
3841
using CcdbApi = o2::ccdb::CcdbApi;
3942

4043
public:
44+
static o2::tof::Diagnostic doDRMerrCalibFromQCHisto(const TH2F* histo, const char* file_output_name);
45+
4146
void resetDia();
4247
CalibTOFapi() = default;
4348
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) {}
49+
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) {}
4550
~CalibTOFapi()
4651
{
4752
if (mLHCphase) {
@@ -53,6 +58,9 @@ class CalibTOFapi
5358
if (mDiaFreq) {
5459
// delete mDiaFreq;
5560
}
61+
if (mDiaDRMFreq) {
62+
// delete mDiaDRMFreq;
63+
}
5664
}
5765

5866
void setTimeStamp(long t)
@@ -69,6 +77,8 @@ class CalibTOFapi
6977
void readTimeSlewingParamFromFile(const char* filename);
7078
void readDiagnosticFrequencies();
7179
void loadDiagnosticFrequencies();
80+
void readDiagnosticDRMFrequencies();
81+
void loadDiagnosticDRMFrequencies();
7282
void readActiveMap();
7383
void loadActiveMap(TOFFEElightInfo* fee);
7484
void writeLHCphase(LhcPhase* phase, std::map<std::string, std::string> metadataLHCphase, uint64_t minTimeSTamp, uint64_t maxTimeStamp);
@@ -89,6 +99,8 @@ class CalibTOFapi
8999
void setLhcPhase(LhcPhase* obj) { mLHCphase = obj; }
90100
Diagnostic* getDiagnostic() { return mDiaFreq; }
91101
void setDiagnostic(Diagnostic* obj) { mDiaFreq = obj; }
102+
Diagnostic* getDiagnosticDRM() { return mDiaDRMFreq; }
103+
void setDiagnosticDRM(Diagnostic* obj) { mDiaDRMFreq = obj; }
92104

93105
int getNoisyThreshold() const { return mNoisyThreshold; }
94106
void setNoisyThreshold(int val) { mNoisyThreshold = val; }
@@ -102,12 +114,39 @@ class CalibTOFapi
102114
void processError(int crate, int trm, int mask);
103115
bool isChannelError(int channel) const;
104116
bool checkTRMPolicy(int mask) const;
117+
void resetDRMErrors();
118+
void processErrorDRM(int crate, int mask);
119+
bool isChannelDRMError(int channel) const;
120+
bool checkDRMPolicy(int mask) const;
121+
122+
void setDRMCriticalErrorMask(uint32_t val) { mDRMCriticalErrorMask = val; }
123+
uint32_t getDRMCriticalErrorMask() const { return mDRMCriticalErrorMask; }
124+
float getDRMprobError(int crate, int type) const { return mErrorInDRM[crate][type]; }
125+
126+
// DRM error codes inherited by EDRMDiagnostic_t in CompressedDataFormat.h (shifted by 4 bits)
127+
static const int DRM_ERRINDEX_SHIFT = 4;
128+
enum DRMcodes {
129+
DRM_HEADER_MISSING = o2::tof::diagnostic::DRM_HEADER_MISSING >> DRM_ERRINDEX_SHIFT,
130+
DRM_TRAILER_MISSING = o2::tof::diagnostic::DRM_TRAILER_MISSING >> DRM_ERRINDEX_SHIFT,
131+
DRM_FEEID_MISMATCH = o2::tof::diagnostic::DRM_FEEID_MISMATCH >> DRM_ERRINDEX_SHIFT,
132+
DRM_ORBIT_MISMATCH = o2::tof::diagnostic::DRM_ORBIT_MISMATCH >> DRM_ERRINDEX_SHIFT,
133+
DRM_CRC_MISMATCH = o2::tof::diagnostic::DRM_CRC_MISMATCH >> DRM_ERRINDEX_SHIFT,
134+
DRM_ENAPARTMASK_DIFFER = o2::tof::diagnostic::DRM_ENAPARTMASK_DIFFER >> DRM_ERRINDEX_SHIFT,
135+
DRM_CLOCKSTATUS_WRONG = o2::tof::diagnostic::DRM_CLOCKSTATUS_WRONG >> DRM_ERRINDEX_SHIFT,
136+
DRM_FAULTSLOTMASK_NOTZERO = o2::tof::diagnostic::DRM_FAULTSLOTMASK_NOTZERO >> DRM_ERRINDEX_SHIFT,
137+
DRM_READOUTTIMEOUT_NOTZERO = o2::tof::diagnostic::DRM_READOUTTIMEOUT_NOTZERO >> DRM_ERRINDEX_SHIFT,
138+
DRM_EVENTWORDS_MISMATCH = o2::tof::diagnostic::DRM_EVENTWORDS_MISMATCH >> DRM_ERRINDEX_SHIFT,
139+
DRM_DIAGNOSTIC_SPARE1 = o2::tof::diagnostic::DRM_DIAGNOSTIC_SPARE1 >> DRM_ERRINDEX_SHIFT,
140+
DRM_DECODE_ERROR = o2::tof::diagnostic::DRM_DECODE_ERROR >> DRM_ERRINDEX_SHIFT,
141+
N_DRM_ERRORS = 12
142+
};
105143

106144
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
145+
long mTimeStamp; ///< timeStamp for queries
146+
LhcPhase* mLHCphase = nullptr; ///< object for LHC phase
147+
SlewParam* mSlewParam = nullptr; ///< object for timeslewing (containing info also for offset and problematic)
148+
Diagnostic* mDiaFreq = nullptr; ///< object for Diagnostic Frequency
149+
Diagnostic* mDiaDRMFreq = nullptr; ///< object for Diagnostic Frequency
111150

112151
// info from diagnostic
113152
int mNoisyThreshold = 1; ///< threshold to be noisy
@@ -116,13 +155,17 @@ class CalibTOFapi
116155
std::vector<std::pair<int, float>> mNoisy; ///< probTRMerror
117156
std::vector<std::pair<int, float>> mTRMerrorProb; ///< probTRMerror
118157
std::vector<int> mTRMmask; ///< mask error for TRM
158+
float mErrorInDRM[Geo::kNCrate][N_DRM_ERRORS] = {}; ///< probability of DRM error
159+
uint32_t mDRMCriticalErrorMask = 0; ///< bit mask for critical DRM errors (e.g. Orbit Mismatch -> 1 << 7, see DataFormats/Detectors/TOF/include/DataFormatsTOF/CompressedDataFormat.h)
119160

120-
bool mIsErrorCh[Geo::NCHANNELS] = {}; ///< channels in error (TRM)
121-
std::vector<int> mFillErrChannel; ///< last error channels filled
122-
bool mIsOffCh[Geo::NCHANNELS] = {}; ///< channels in error (TRM)
123-
bool mIsNoisy[Geo::NCHANNELS] = {}; ///< noisy channels
161+
bool mIsErrorCh[Geo::NCHANNELS] = {}; ///< channels in error (TRM)
162+
std::vector<int> mFillErrChannel; ///< last error channels filled
163+
bool mIsOffCh[Geo::NCHANNELS] = {}; ///< channels in error (TRM)
164+
bool mIsNoisy[Geo::NCHANNELS] = {}; ///< noisy channels
165+
bool mIsErrorDRMCh[Geo::NCHANNELS] = {}; ///< channels in error (DRM)
166+
std::vector<int> mFillErrDRMChannel; ///< last error channels filled
124167

125-
ClassDefNV(CalibTOFapi, 1);
168+
ClassDefNV(CalibTOFapi, 2);
126169
};
127170
} // namespace tof
128171
} // namespace o2

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,24 +98,32 @@ class Digit
9898
double getT0true() const { return mT0true; }
9999
void setT0true(double val) { mT0true = val; }
100100

101+
int8_t getErrorCode() const { return mErrorCode; }
102+
void setErrorCode(int8_t err) { mErrorCode = err; }
103+
void addDRMError() { mErrorCode |= 2; }
104+
bool hasDRMError() const { return mErrorCode & 2; }
105+
void addTRMError() { mErrorCode |= 1; }
106+
bool hasTRMError() const { return mErrorCode & 1; }
107+
101108
private:
102109
friend class boost::serialization::access;
103110

104-
Int_t mChannel; ///< TOF channel index
105-
uint16_t mTDC; ///< TDC bin number
106-
uint16_t mTOT; ///< TOT bin number
107-
InteractionRecord mIR{0, 0}; ///< InteractionRecord (orbit and bc) when digit occurs
108-
Int_t mLabel; ///< Index of the corresponding entry in the MC label array
109-
Double_t mCalibratedTime; //!< time of the digits after calibration (not persistent; it will be filled during clusterization)
110-
Int_t mElectronIndex; //!/< index in electronic format
111+
Int_t mChannel; ///< TOF channel index
112+
uint16_t mTDC; ///< TDC bin number
113+
uint16_t mTOT; ///< TOT bin number
114+
InteractionRecord mIR{0, 0}; ///< InteractionRecord (orbit and bc) when digit occurs
115+
Int_t mLabel; ///< Index of the corresponding entry in the MC label array
116+
Double_t mCalibratedTime; //!< time of the digits after calibration (not persistent; it will be filled during clusterization)
117+
Int_t mElectronIndex; //!/< index in electronic format
111118
uint32_t mTriggerOrbit = 0; //!< orbit id of trigger event // RS: orbit must be 32bits long
112119
uint16_t mTriggerBunch = 0; //!< bunch id of trigger event
113120
Bool_t mIsUsedInCluster; //!/< flag to declare that the digit was used to build a cluster
114121
Bool_t mIsProblematic = false; //!< flag to tell whether the channel of the digit was problemati; not persistent; default = ok
115122
float mTgeant = 0.0; ///< geant time in MC
116123
double mT0true = 0.0; ///< t0true
124+
int8_t mErrorCode = 0; ///< if TRM o DRM error
117125

118-
ClassDefNV(Digit, 5);
126+
ClassDefNV(Digit, 6);
119127
};
120128

121129
std::ostream& operator<<(std::ostream& stream, const Digit& dig);

Detectors/TOF/base/src/CalibTOFapi.cxx

Lines changed: 117 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 <= Geo::kNCrate; 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,34 @@ void CalibTOFapi::loadDiagnosticFrequencies()
210251

211252
//______________________________________________________________________
212253

254+
void CalibTOFapi::loadDiagnosticDRMFrequencies()
255+
{
256+
mDiaDRMFreq->print();
257+
258+
for (int ic = 0; ic < Geo::kNCrate; ic++) { // loop over crates
259+
float DRMcounters = mDiaDRMFreq->getFrequencyDRM(ic);
260+
261+
if (DRMcounters < 1) {
262+
for (int ie = 0; ie < N_DRM_ERRORS; ie++) {
263+
mErrorInDRM[ic][ie] = 0.;
264+
}
265+
continue;
266+
}
267+
268+
for (int ie = 0; ie < N_DRM_ERRORS; ie++) { // loop over error types
269+
int ie_shifted = ie + DRM_ERRINDEX_SHIFT;
270+
271+
float frequency = mDiaDRMFreq->getFrequencyDRMerror(ic, ie_shifted) * 1. / DRMcounters; // error frequency
272+
if (frequency > 1) {
273+
frequency = 1.;
274+
}
275+
mErrorInDRM[ic][ie] = frequency;
276+
}
277+
}
278+
}
279+
280+
//______________________________________________________________________
281+
213282
void CalibTOFapi::writeLHCphase(LhcPhase* phase, std::map<std::string, std::string> metadataLHCphase, uint64_t minTimeStamp, uint64_t maxTimeStamp)
214283
{
215284

@@ -330,6 +399,17 @@ void CalibTOFapi::resetTRMErrors()
330399

331400
//______________________________________________________________________
332401

402+
void CalibTOFapi::resetDRMErrors()
403+
{
404+
for (auto index : mFillErrDRMChannel) {
405+
mIsErrorDRMCh[index] = false;
406+
}
407+
408+
mFillErrDRMChannel.clear();
409+
}
410+
411+
//______________________________________________________________________
412+
333413
void CalibTOFapi::processError(int crate, int trm, int mask)
334414
{
335415
if (checkTRMPolicy(mask)) { // check the policy of TRM -> true=good TRM
@@ -348,14 +428,50 @@ void CalibTOFapi::processError(int crate, int trm, int mask)
348428

349429
//______________________________________________________________________
350430

431+
void CalibTOFapi::processErrorDRM(int crate, int mask)
432+
{
433+
if (checkDRMPolicy(mask)) {
434+
return;
435+
}
436+
437+
for (int trm = 3; trm < 13; trm++) {
438+
int ech = (crate << 12) + ((trm - 3) << 8);
439+
for (int i = ech; i < ech + 256; i++) {
440+
int channel = Geo::getCHFromECH(i);
441+
if (channel == -1 || mIsErrorDRMCh[channel] == true) {
442+
continue;
443+
}
444+
445+
mIsErrorDRMCh[channel] = true;
446+
mFillErrDRMChannel.push_back(channel);
447+
}
448+
}
449+
}
450+
451+
//______________________________________________________________________
452+
351453
bool CalibTOFapi::checkTRMPolicy(int mask) const
352454
{
353455
return false;
354456
}
355457

356458
//______________________________________________________________________
357459

460+
bool CalibTOFapi::checkDRMPolicy(int mask) const
461+
{
462+
return false;
463+
}
464+
465+
//______________________________________________________________________
466+
358467
bool CalibTOFapi::isChannelError(int channel) const
359468
{
360469
return mIsErrorCh[channel];
361470
}
471+
472+
//______________________________________________________________________
473+
474+
bool CalibTOFapi::isChannelDRMError(int channel) const
475+
{
476+
return mIsErrorDRMCh[channel];
477+
}

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/)

0 commit comments

Comments
 (0)