diff --git a/DataFormats/Detectors/TOF/include/DataFormatsTOF/Diagnostic.h b/DataFormats/Detectors/TOF/include/DataFormatsTOF/Diagnostic.h index 8adcdb63e9d21..028da04b3ef70 100644 --- a/DataFormats/Detectors/TOF/include/DataFormatsTOF/Diagnostic.h +++ b/DataFormats/Detectors/TOF/include/DataFormatsTOF/Diagnostic.h @@ -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(); } diff --git a/Detectors/TOF/base/include/TOFBase/CalibTOFapi.h b/Detectors/TOF/base/include/TOFBase/CalibTOFapi.h index c3d39d3e978e1..23a4bac9134f4 100644 --- a/Detectors/TOF/base/include/TOFBase/CalibTOFapi.h +++ b/Detectors/TOF/base/include/TOFBase/CalibTOFapi.h @@ -24,6 +24,8 @@ #include "DataFormatsTOF/Diagnostic.h" #include "DataFormatsTOF/TOFFEElightInfo.h" +class TH2F; + namespace o2 { namespace tof @@ -38,6 +40,8 @@ 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); diff --git a/Detectors/TOF/base/src/CalibTOFapi.cxx b/Detectors/TOF/base/src/CalibTOFapi.cxx index 281498990a9dd..ab313b60520b4 100644 --- a/Detectors/TOF/base/src/CalibTOFapi.cxx +++ b/Detectors/TOF/base/src/CalibTOFapi.cxx @@ -11,11 +11,40 @@ #include "TOFBase/CalibTOFapi.h" #include // for LOG +#include 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); diff --git a/Detectors/TOF/prototyping/CMakeLists.txt b/Detectors/TOF/prototyping/CMakeLists.txt index 1ce2268f1358a..7dfc9f8cb7361 100644 --- a/Detectors/TOF/prototyping/CMakeLists.txt +++ b/Detectors/TOF/prototyping/CMakeLists.txt @@ -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 @@ -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/) diff --git a/Detectors/TOF/prototyping/checkDRMobj_tof.C b/Detectors/TOF/prototyping/checkDRMobj_tof.C new file mode 100644 index 0000000000000..0f5438755bbee --- /dev/null +++ b/Detectors/TOF/prototyping/checkDRMobj_tof.C @@ -0,0 +1,30 @@ +#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); +} diff --git a/Detectors/TOF/prototyping/makeDRMobj_tof.C b/Detectors/TOF/prototyping/makeDRMobj_tof.C new file mode 100644 index 0000000000000..b8dfb1d7635b4 --- /dev/null +++ b/Detectors/TOF/prototyping/makeDRMobj_tof.C @@ -0,0 +1,27 @@ +#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) +{ + TFile* f = new TFile(inputfile); + TH2F* h = (TH2F*)f->Get("ccdb_object"); + + o2::tof::Diagnostic drmDia; + + if (!dummy) { + drmDia = o2::tof::CalibTOFapi::doDRMerrCalibFromQCHisto(h, "ccdb.root"); + return; + } + + // continue if dummy + 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(); +}