Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class Diagnostic
uint32_t fillEmptyTOF(uint32_t frequency = 1) { return fill(1, frequency); }
static ULong64_t getEmptyCrateKey(int crate);
static ULong64_t getNoisyChannelKey(int channel);
static ULong64_t getDRMKey(int crate) { return 1000000 + crate * 1000; }
static ULong64_t getDRMerrorKey(int crate, int error) { return getDRMKey(crate) + error; }
uint32_t getFrequencyDRM(int crate) const { return getFrequency(getDRMKey(crate)); }
uint32_t getFrequencyDRMerror(int crate, int error) const { return getFrequency(getDRMerrorKey(crate, error)); }
uint32_t fillDRM(int crate, uint32_t frequency) { return fill(getDRMKey(crate), frequency); }
uint32_t fillDRMerror(int crate, int error, uint32_t frequency) { return fill(getDRMerrorKey(crate, error), frequency); }

static ULong64_t getTRMKey(int crate, int trm);
void print(bool longFormat = false) const;
void clear() { mVector.clear(); }
Expand Down
63 changes: 53 additions & 10 deletions Detectors/TOF/base/include/TOFBase/CalibTOFapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include "TOFBase/Geo.h"
#include "DataFormatsTOF/Diagnostic.h"
#include "DataFormatsTOF/TOFFEElightInfo.h"
#include "DataFormatsTOF/CompressedDataFormat.h"

class TH2F;

namespace o2
{
Expand All @@ -38,10 +41,12 @@ class CalibTOFapi
using CcdbApi = o2::ccdb::CcdbApi;

public:
static o2::tof::Diagnostic doDRMerrCalibFromQCHisto(const TH2F* histo, const char* file_output_name);

void resetDia();
CalibTOFapi() = default;
CalibTOFapi(const std::string url);
CalibTOFapi(long timestamp, o2::dataformats::CalibLHCphaseTOF* phase, o2::dataformats::CalibTimeSlewingParamTOF* slew, Diagnostic* dia = nullptr) : mTimeStamp(timestamp), mLHCphase(phase), mSlewParam(slew), mDiaFreq(dia) {}
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) {}
~CalibTOFapi()
{
if (mLHCphase) {
Expand All @@ -53,6 +58,9 @@ class CalibTOFapi
if (mDiaFreq) {
// delete mDiaFreq;
}
if (mDiaDRMFreq) {
// delete mDiaDRMFreq;
}
}

void setTimeStamp(long t)
Expand All @@ -69,6 +77,8 @@ class CalibTOFapi
void readTimeSlewingParamFromFile(const char* filename);
void readDiagnosticFrequencies();
void loadDiagnosticFrequencies();
void readDiagnosticDRMFrequencies();
void loadDiagnosticDRMFrequencies();
void readActiveMap();
void loadActiveMap(TOFFEElightInfo* fee);
void writeLHCphase(LhcPhase* phase, std::map<std::string, std::string> metadataLHCphase, uint64_t minTimeSTamp, uint64_t maxTimeStamp);
Expand All @@ -89,6 +99,8 @@ class CalibTOFapi
void setLhcPhase(LhcPhase* obj) { mLHCphase = obj; }
Diagnostic* getDiagnostic() { return mDiaFreq; }
void setDiagnostic(Diagnostic* obj) { mDiaFreq = obj; }
Diagnostic* getDiagnosticDRM() { return mDiaDRMFreq; }
void setDiagnosticDRM(Diagnostic* obj) { mDiaDRMFreq = obj; }

int getNoisyThreshold() const { return mNoisyThreshold; }
void setNoisyThreshold(int val) { mNoisyThreshold = val; }
Expand All @@ -102,12 +114,39 @@ class CalibTOFapi
void processError(int crate, int trm, int mask);
bool isChannelError(int channel) const;
bool checkTRMPolicy(int mask) const;
void resetDRMErrors();
void processErrorDRM(int crate, int mask);
bool isChannelDRMError(int channel) const;
bool checkDRMPolicy(int mask) const;

void setDRMCriticalErrorMask(uint32_t val) { mDRMCriticalErrorMask = val; }
uint32_t getDRMCriticalErrorMask() const { return mDRMCriticalErrorMask; }
float getDRMprobError(int crate, int type) const { return mErrorInDRM[crate][type]; }

// DRM error codes inherited by EDRMDiagnostic_t in CompressedDataFormat.h (shifted by 4 bits)
static const int DRM_ERRINDEX_SHIFT = 4;
enum DRMcodes {
DRM_HEADER_MISSING = o2::tof::diagnostic::DRM_HEADER_MISSING >> DRM_ERRINDEX_SHIFT,
DRM_TRAILER_MISSING = o2::tof::diagnostic::DRM_TRAILER_MISSING >> DRM_ERRINDEX_SHIFT,
DRM_FEEID_MISMATCH = o2::tof::diagnostic::DRM_FEEID_MISMATCH >> DRM_ERRINDEX_SHIFT,
DRM_ORBIT_MISMATCH = o2::tof::diagnostic::DRM_ORBIT_MISMATCH >> DRM_ERRINDEX_SHIFT,
DRM_CRC_MISMATCH = o2::tof::diagnostic::DRM_CRC_MISMATCH >> DRM_ERRINDEX_SHIFT,
DRM_ENAPARTMASK_DIFFER = o2::tof::diagnostic::DRM_ENAPARTMASK_DIFFER >> DRM_ERRINDEX_SHIFT,
DRM_CLOCKSTATUS_WRONG = o2::tof::diagnostic::DRM_CLOCKSTATUS_WRONG >> DRM_ERRINDEX_SHIFT,
DRM_FAULTSLOTMASK_NOTZERO = o2::tof::diagnostic::DRM_FAULTSLOTMASK_NOTZERO >> DRM_ERRINDEX_SHIFT,
DRM_READOUTTIMEOUT_NOTZERO = o2::tof::diagnostic::DRM_READOUTTIMEOUT_NOTZERO >> DRM_ERRINDEX_SHIFT,
DRM_EVENTWORDS_MISMATCH = o2::tof::diagnostic::DRM_EVENTWORDS_MISMATCH >> DRM_ERRINDEX_SHIFT,
DRM_DIAGNOSTIC_SPARE1 = o2::tof::diagnostic::DRM_DIAGNOSTIC_SPARE1 >> DRM_ERRINDEX_SHIFT,
DRM_DECODE_ERROR = o2::tof::diagnostic::DRM_DECODE_ERROR >> DRM_ERRINDEX_SHIFT,
N_DRM_ERRORS = 12
};

private:
long mTimeStamp; ///< timeStamp for queries
LhcPhase* mLHCphase = nullptr; ///< object for LHC phase
SlewParam* mSlewParam = nullptr; ///< object for timeslewing (containing info also for offset and problematic)
Diagnostic* mDiaFreq = nullptr; ///< object for Diagnostic Frequency
long mTimeStamp; ///< timeStamp for queries
LhcPhase* mLHCphase = nullptr; ///< object for LHC phase
SlewParam* mSlewParam = nullptr; ///< object for timeslewing (containing info also for offset and problematic)
Diagnostic* mDiaFreq = nullptr; ///< object for Diagnostic Frequency
Diagnostic* mDiaDRMFreq = nullptr; ///< object for Diagnostic Frequency

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

bool mIsErrorCh[Geo::NCHANNELS] = {}; ///< channels in error (TRM)
std::vector<int> mFillErrChannel; ///< last error channels filled
bool mIsOffCh[Geo::NCHANNELS] = {}; ///< channels in error (TRM)
bool mIsNoisy[Geo::NCHANNELS] = {}; ///< noisy channels
bool mIsErrorCh[Geo::NCHANNELS] = {}; ///< channels in error (TRM)
std::vector<int> mFillErrChannel; ///< last error channels filled
bool mIsOffCh[Geo::NCHANNELS] = {}; ///< channels in error (TRM)
bool mIsNoisy[Geo::NCHANNELS] = {}; ///< noisy channels
bool mIsErrorDRMCh[Geo::NCHANNELS] = {}; ///< channels in error (DRM)
std::vector<int> mFillErrDRMChannel; ///< last error channels filled

ClassDefNV(CalibTOFapi, 1);
ClassDefNV(CalibTOFapi, 2);
};
} // namespace tof
} // namespace o2
Expand Down
24 changes: 16 additions & 8 deletions Detectors/TOF/base/include/TOFBase/Digit.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,32 @@ class Digit
double getT0true() const { return mT0true; }
void setT0true(double val) { mT0true = val; }

int8_t getErrorCode() const { return mErrorCode; }
void setErrorCode(int8_t err) { mErrorCode = err; }
void addDRMError() { mErrorCode |= 2; }
bool hasDRMError() const { return mErrorCode & 2; }
void addTRMError() { mErrorCode |= 1; }
bool hasTRMError() const { return mErrorCode & 1; }

private:
friend class boost::serialization::access;

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

ClassDefNV(Digit, 5);
ClassDefNV(Digit, 6);
};

std::ostream& operator<<(std::ostream& stream, const Digit& dig);
Expand Down
118 changes: 117 additions & 1 deletion Detectors/TOF/base/src/CalibTOFapi.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,40 @@

#include "TOFBase/CalibTOFapi.h"
#include <fairlogger/Logger.h> // for LOG
#include <TH2F.h>

using namespace o2::tof;

ClassImp(o2::tof::CalibTOFapi);

o2::tof::Diagnostic CalibTOFapi::doDRMerrCalibFromQCHisto(const TH2F* histo, const char* file_output_name)
{
// 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)
// 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
o2::tof::Diagnostic drmDia;

for (int j = 1; j <= Geo::kNCrate; j++) {
drmDia.fillDRM(j - 1, histo->GetBinContent(1, j));
for (int i = 2; i <= histo->GetXaxis()->GetNbins(); i++) {
if (histo->GetBinContent(1, j)) {
if (histo->GetBinContent(i, j) > 0) {
drmDia.fillDRMerror(j - 1, i - 1, histo->GetBinContent(i, j));
}
}
}
}

TFile* fo = new TFile(file_output_name, "RECREATE");
fo->WriteObjectAny(&drmDia, drmDia.Class_Name(), "ccdb_object");
fo->Close();
LOG(info) << "DRM error ccdb object created in " << file_output_name << " with this content";
drmDia.print(true);

return drmDia;
}

//______________________________________________________________________

void CalibTOFapi::resetDia()
{
memset(mEmptyCrateProb, 0., Geo::kNCrate * 4);
Expand Down Expand Up @@ -116,11 +145,23 @@ void CalibTOFapi::readDiagnosticFrequencies()
{
auto& mgr = CcdbManager::instance();
long timems = long(mTimeStamp) * 1000;
LOG(info) << "TOF get Diagnostics with timestamp (ms) = " << timems;
LOG(info) << "TOF get TRM Diagnostics with timestamp (ms) = " << timems;
mDiaFreq = mgr.getForTimeStamp<Diagnostic>("TOF/Calib/Diagnostic", timems);

loadDiagnosticFrequencies();
}

//______________________________________________________________________

void CalibTOFapi::readDiagnosticDRMFrequencies()
{
auto& mgr = CcdbManager::instance();
long timems = long(mTimeStamp) * 1000;
LOG(info) << "TOF get DRM Diagnostics with timestamp (ms) = " << timems;
mDiaFreq = mgr.getForTimeStamp<Diagnostic>("TOF/Calib/TRMerrors", timems);

loadDiagnosticDRMFrequencies();
}
//______________________________________________________________________

void CalibTOFapi::loadDiagnosticFrequencies()
Expand Down Expand Up @@ -210,6 +251,34 @@ void CalibTOFapi::loadDiagnosticFrequencies()

//______________________________________________________________________

void CalibTOFapi::loadDiagnosticDRMFrequencies()
{
mDiaDRMFreq->print();

for (int ic = 0; ic < Geo::kNCrate; ic++) { // loop over crates
float DRMcounters = mDiaDRMFreq->getFrequencyDRM(ic);

if (DRMcounters < 1) {
for (int ie = 0; ie < N_DRM_ERRORS; ie++) {
mErrorInDRM[ic][ie] = 0.;
}
continue;
}

for (int ie = 0; ie < N_DRM_ERRORS; ie++) { // loop over error types
int ie_shifted = ie + DRM_ERRINDEX_SHIFT;

float frequency = mDiaDRMFreq->getFrequencyDRMerror(ic, ie_shifted) * 1. / DRMcounters; // error frequency
if (frequency > 1) {
frequency = 1.;
}
mErrorInDRM[ic][ie] = frequency;
}
}
}

//______________________________________________________________________

void CalibTOFapi::writeLHCphase(LhcPhase* phase, std::map<std::string, std::string> metadataLHCphase, uint64_t minTimeStamp, uint64_t maxTimeStamp)
{

Expand Down Expand Up @@ -330,6 +399,17 @@ void CalibTOFapi::resetTRMErrors()

//______________________________________________________________________

void CalibTOFapi::resetDRMErrors()
{
for (auto index : mFillErrDRMChannel) {
mIsErrorDRMCh[index] = false;
}

mFillErrDRMChannel.clear();
}

//______________________________________________________________________

void CalibTOFapi::processError(int crate, int trm, int mask)
{
if (checkTRMPolicy(mask)) { // check the policy of TRM -> true=good TRM
Expand All @@ -348,14 +428,50 @@ void CalibTOFapi::processError(int crate, int trm, int mask)

//______________________________________________________________________

void CalibTOFapi::processErrorDRM(int crate, int mask)
{
if (checkDRMPolicy(mask)) {
return;
}

for (int trm = 3; trm < 13; trm++) {
int ech = (crate << 12) + ((trm - 3) << 8);
for (int i = ech; i < ech + 256; i++) {
int channel = Geo::getCHFromECH(i);
if (channel == -1 || mIsErrorDRMCh[channel] == true) {
continue;
}

mIsErrorDRMCh[channel] = true;
mFillErrDRMChannel.push_back(channel);
}
}
}

//______________________________________________________________________

bool CalibTOFapi::checkTRMPolicy(int mask) const
{
return false;
}

//______________________________________________________________________

bool CalibTOFapi::checkDRMPolicy(int mask) const
{
return false;
}

//______________________________________________________________________

bool CalibTOFapi::isChannelError(int channel) const
{
return mIsErrorCh[channel];
}

//______________________________________________________________________

bool CalibTOFapi::isChannelDRMError(int channel) const
{
return mIsErrorDRMCh[channel];
}
15 changes: 15 additions & 0 deletions Detectors/TOF/prototyping/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ o2_add_test_root_macro(findLabels.C
O2::TOFBase
LABELS tof)

o2_add_test_root_macro(makeDRMobj_tof.C
PUBLIC_LINK_LIBRARIES O2::DataFormatsTOF
O2::TOFBase
LABELS tof)

o2_add_test_root_macro(checkDRMobj_tof.C
PUBLIC_LINK_LIBRARIES O2::DataFormatsTOF
O2::TOFBase
LABELS tof)

o2_add_test_root_macro(findTOFclusterFromLabel.C
PUBLIC_LINK_LIBRARIES O2::DataFormatsTOF
O2::SimulationDataFormat
Expand Down Expand Up @@ -59,3 +69,8 @@ o2_add_test_root_macro(macroEvTime.C
PUBLIC_LINK_LIBRARIES O2::TOFBase
O2::TOFReconstruction
LABELS tof)

install(
FILES makeDRMobj_tof.C
checkDRMobj_tof.C
DESTINATION share/macro/)
Loading
Loading