Skip to content
Closed
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
29 changes: 23 additions & 6 deletions Detectors/TOF/base/include/TOFBase/CalibTOFapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "DataFormatsTOF/Diagnostic.h"
#include "DataFormatsTOF/TOFFEElightInfo.h"

class TH2F;

namespace o2
{
namespace tof
Expand All @@ -38,10 +40,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 +57,9 @@ class CalibTOFapi
if (mDiaFreq) {
// delete mDiaFreq;
}
if (mDiaDRMFreq) {
// delete mDiaDRMFreq;
}
}

void setTimeStamp(long t)
Expand All @@ -69,6 +76,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 +98,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 @@ -103,11 +114,15 @@ class CalibTOFapi
bool isChannelError(int channel) const;
bool checkTRMPolicy(int mask) const;

void setDRMCriticalErrorMask(uint32_t val) { mDRMCriticalErrorMask = val; }
uint32_t getDRMCriticalErrorMask() const { return mDRMCriticalErrorMask; }

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 +131,15 @@ 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[72] = {}; ///< 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

ClassDefNV(CalibTOFapi, 1);
ClassDefNV(CalibTOFapi, 2);
};
} // namespace tof
} // namespace o2
Expand Down
73 changes: 72 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 <= 72; 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,36 @@ void CalibTOFapi::loadDiagnosticFrequencies()

//______________________________________________________________________

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

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

if (DRMcounters < 1) {
mErrorInDRM[ic] = 0.;
continue;
}

float probGood = 1;

for (int ie = 0; ie < 28; ie++) { // loop over error types
uint32_t bitError = 1 << ie;
if (bitError & mDRMCriticalErrorMask) { // if error has to be masked
float frequency = mDiaDRMFreq->getFrequencyDRMerror(ic, ie) * 1. / mErrorInDRM[ic]; // error frequency
if (frequency > 1) {
frequency = 1.;
}
probGood *= (1 - frequency); // frequency of no error assuming all types are independent
}
}
mErrorInDRM[ic] = 1 - probGood; // probability of at least one error to be masked
}
}

//______________________________________________________________________

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

Expand Down
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/)
41 changes: 41 additions & 0 deletions Detectors/TOF/prototyping/checkDRMobj_tof.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#if !defined(__CLING__) || defined(__ROOTCLING__)
#include "TFile.h"
#include "TH2F.h"
#include "TOFBase/CalibTOFapi.h"
#endif

void checkDRMobj_tof(const char* fname = "ccdb.root")
{
TFile* f = new TFile(fname);

TH2F* hErrors = new TH2F("hDRMerrors", ";error code; frequency", 30, 0, 30, 72, 0, 72);

o2::tof::Diagnostic* drmDia = (o2::tof::Diagnostic*)f->Get("ccdb_object");

for (int j = 1; j <= 72; j++) {
uint32_t patternRDH = o2::tof::Diagnostic::getDRMKey(j - 1);
for (int i = 1; i <= hErrors->GetXaxis()->GetNbins(); i++) {
uint32_t pattern = o2::tof::Diagnostic::getDRMerrorKey(j - 1, i - 1);
if (drmDia->getFrequency(patternRDH)) {
hErrors->SetBinContent(i, j, drmDia->getFrequency(pattern) * 1. / drmDia->getFrequency(patternRDH));
}
}
}

TCanvas* c = new TCanvas();
c->cd(1);
hErrors->Draw("colz");

drmDia->print(true);
}
39 changes: 39 additions & 0 deletions Detectors/TOF/prototyping/makeDRMobj_tof.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#if !defined(__CLING__) || defined(__ROOTCLING__)
#include "TFile.h"
#include "TH2F.h"
#include "TOFBase/CalibTOFapi.h"
#endif

void makeDRMobj_tof(const char* inputfile = "TObject_1764607157510.root", bool dummy = false)
{
if (dummy) {
o2::tof::Diagnostic drmDia;
for (int j = 1; j <= 72; j++) {
drmDia.fill(o2::tof::Diagnostic::getDRMKey(j - 1));
}

TFile* fo = new TFile("ccdb.root", "RECREATE");
fo->WriteObjectAny(&drmDia, drmDia.Class_Name(), "ccdb_object");
fo->Close();

return;
}

TFile* f = new TFile(inputfile);
TH2F* h = (TH2F*)f->Get("ccdb_object");

o2::tof::Diagnostic drmDia;

drmDia = o2::tof::CalibTOFapi::doDRMerrCalibFromQCHisto(h, "ccdb.root");
}
4 changes: 3 additions & 1 deletion Steer/DigitizerWorkflow/src/SimpleDigitizerWorkflow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
// option to use/not use CCDB for TOF
workflowOptions.push_back(ConfigParamSpec{"use-ccdb-tof", o2::framework::VariantType::Bool, false, {"enable access to ccdb tof calibration objects"}});
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)"}});
workflowOptions.push_back(ConfigParamSpec{"tof-drm-bitmask", o2::framework::VariantType::Int, 128, {"bit mask of DRM critical errors"}}); // 128 = orbit mismatch

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

digitizerSpecs.emplace_back(o2::tof::getTOFDigitizerSpec(fanoutsize++, useCCDB, mctruth, ccdb_url_tof.c_str(), timestamp));
digitizerSpecs.emplace_back(o2::tof::getTOFDigitizerSpec(fanoutsize++, useCCDB, mctruth, ccdb_url_tof.c_str(), timestamp, maskDRM));
// add TOF digit writer
writerSpecs.emplace_back(o2::tof::getTOFDigitWriterSpec(mctruth));
}
Expand Down
Loading
Loading