From 13e19c57a347b37cd7202a7c31630c0ededb6b56 Mon Sep 17 00:00:00 2001 From: wpierozak Date: Thu, 18 Dec 2025 13:46:51 +0100 Subject: [PATCH 01/14] FT0: created first sketch of implementation of generation of TVX per Event calibration object --- Detectors/FIT/FT0/calibration/CMakeLists.txt | 7 ++ .../FT0Calibration/EventsPerBcCalibrator.h | 56 +++++++++++++++ .../calibration/src/EventsPerBcCalibrator.cxx | 53 +++++++++++++++ .../FT0EventsPerBcProcessor-Workflow.cxx | 68 +++++++++++++++++++ 4 files changed, 184 insertions(+) create mode 100644 Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h create mode 100644 Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx create mode 100644 Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx diff --git a/Detectors/FIT/FT0/calibration/CMakeLists.txt b/Detectors/FIT/FT0/calibration/CMakeLists.txt index d103b4a9a18b6..52acae2fbacc7 100644 --- a/Detectors/FIT/FT0/calibration/CMakeLists.txt +++ b/Detectors/FIT/FT0/calibration/CMakeLists.txt @@ -33,3 +33,10 @@ o2_add_library(FT0Calibration PUBLIC_LINK_LIBRARIES O2::FT0Calibration ) + o2_add_executable(ft0-events-per-bc-processor + COMPONENT_NAME calibration + SOURCES workflow/FT0EventsPerBcProcessor-Workflow.cxx + PUBLIC_LINK_LIBRARIES + O2::FT0Calibration + ) + \ No newline at end of file diff --git a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h new file mode 100644 index 0000000000000..e96da70f0103a --- /dev/null +++ b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h @@ -0,0 +1,56 @@ +#ifndef O2_FT0TVXPERBCID +#define O2_FT0TVXPERBCID + +#include +#include + +#include "CommonDataFormat/FlatHisto2D.h" +#include "CommonConstants/LHCConstants.h" +#include "DataFormatsFT0/SpectraInfoObject.h" +#include "DetectorsCalibration/TimeSlotCalibration.h" +#include "DetectorsCalibration/TimeSlot.h" +#include "DataFormatsFT0/BcEvents.h" + +namespace o2::ft0 +{ + struct EventsPerBc + { + EventsPerBc() = default; + + size_t getEntries() const { return entries; } + void print() const; + void fill(const gsl::span data); + void merge(const EventsPerBc* prev); + + std::array mTvx{0.0}; + size_t entries{0}; + long startTimeStamp{0}; + long stopTimeStamp{0}; + }; + + class EventsPerBcCalibrator final : public o2::calibration::TimeSlotCalibration + { + using Slot = o2::calibration::TimeSlot; + using TFType = o2::calibration::TFType; + + public: + EventsPerBcCalibrator() + { + setUpdateAtTheEndOfRunOnly(); + } + + bool hasEnoughData(const Slot& slot) const final { return true; } + void initOutput() final; + void finalizeSlot(Slot& slot) final; + Slot& emplaceNewSlot(bool front, TFType tstart, TFType tend) final; + + const TH1F* getTvxPerBc() { return mTvxPerBc.get(); } + const CcdbObjectInfo* getTvxPerBcCcdbInfo() { return mTvxPerBcInfo.get(); } + + private: + std::unique_ptr mTvxPerBc; + std::unique_ptr mTvxPerBcInfo; + }; +} + +#endif diff --git a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx new file mode 100644 index 0000000000000..718a1a96e71cc --- /dev/null +++ b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx @@ -0,0 +1,53 @@ +#include "FT0Calibration/EventsPerBcCalibrator.h" + +namespace o2::ft0 +{ + void EventsPerBc::print() const + { + + } + + void EventsPerBc::fill(const gsl::span data) + { + for(const auto& digit: digits) { + double isVertex = digit.mTriggers.isVertex(); + mTvx[digits.mIntRecord.bc] += isVertex; + entries += isVertex; + } + } + + void EventsPerBc::merge(const EventsPerBc* prev) + { + for(int bc = 0; bc < o2::constants::lhc::LHCMaxBunches; bc++){ + mTvx[bc] += prev->mTvx[bc]; + } + entries += prev->mEntries; + } + + void EventsPerBcCalibrator::initOutput() final + { + mTvxPerBc.reset(); + mTvxPerBcInfo.reset(); + } + + void EventsPerBcCalibrator::finalizeSlot(EventsPerBcCalibrator::Slot& slot) final + { + o2::ft0::EventsPerBc* data = slot.getContainer(); + mTvxPerBc = std::make_unique("TvxPerBc", "FT0 TVX per BC", o2::constants::lhc::LHCMaxBunches, 0, o2::constants::lhc::LHCMaxBunches - 1); + for(int bin = 0; bin < o2::constants::lhc::LHCMaxBunches; bin++) { + tvxsHist->fill(bin, data->mTvx[bin]); + } + auto clName = o2::utils::MemFileHelper::getClassName(*tvxsHist); + auto flName = o2::ccdb::CcdbApi::generateFileName(clName); + std::map metaData; + mTvxPerBcInfo = std::make_unique("FT0/Calib/TvxPerBc", clName, flName, metaData, slot.getStarTimeMs(), slot.getEndTimeStampMS()); + } + + EventsPerBcCalibrator::Slot& EventsPerBcCalibrator::emplaceNewSlot(bool front, TFType tstart, TFType tend) final + { + auto& cont = getSlots(); + auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend); + slot.setContainer(std::make_unique()); + return slot; + } +} \ No newline at end of file diff --git a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx new file mode 100644 index 0000000000000..5a5fcdbc1b8e8 --- /dev/null +++ b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx @@ -0,0 +1,68 @@ +#include "Framework/runDataProcessing.h" +#include "CommonUtils/ConfigurableParam.h" +#include "Framework/ConfigParamSpec.h" +#include +#include "Framework/DeviceSpec.h" +#include "Framework/WorkflowSpec.h" +#include "Framework/Task.h" + +#include "DataFormatsFT0/Digit.h" +#include "DataFormatsFT0/BcEvents.h" +#include "FT0Calibration/EventsPerBcCalibrator.h" + +namespace o2::ft0 +{ + class FT0EventsPerBcProcessor final : public o2::framework::Task + { + void init(o2::framework::InitContext& ic) final + { + mCalibrator = std::make_unique(); + } + + void run(o2::framework::ProcessContext& pc) final + { + auto digits = pc.inputs().get>("digits"); + mCalibrator->process(digits); + } + + void endOfStream(o2::framework::EndOfStreamContext& ec) final + { + mCalibrator->chekSlotToFinalize(); + sendOutput(ec.outputs()); + mCalibrator->initOutput(); + } + + void sendOutput(DataAllocator& output) + { + TH1F* tvxHist = mCalibrator->getTvxPerBc(); + CcdbObjectInfo* info = mCalibrator->getTvxPerBcCcdbInfo(); + auto image = o2::ccdb::CcdbApi::createObjectImage(tvxHist, info); + LOG(info) << "Sending object to CCDB"; + output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "EVENTS_PER_BC_INFO", 0}, *image.get()); + output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "EVENTS_PER_BC_INFO", 0}, info); + } + + private: + std::unique_ptr mCalibrator; + }; +} + +WorkflowSpec defineDataProcessing(ConfigContext& const & cfgc) +{ + using namespace o2::framework; + std::vector inputs; + inputs.emplace_back("digits", "FT0", "DIGITSBC"); + std::vector outputs; + outputs.emplace_back("eventsPerBcInfo", "FT0", "EVENTS_PER_BC_INFO") + DataProcessorSpec dataProcessorSpec{ + "FT0EventsPerBcProcessor", + inputs, + outputs, + AlgorithmSpec(adaptFromTask()), + Options{} + }; + + WorkflowSpec workflow; + workflow.emplace_back(dataProcessorSpec); + return workflow; +} \ No newline at end of file From 24919bbc5dec9feb24b76ac44064c3b5d3301bca Mon Sep 17 00:00:00 2001 From: wpierozak Date: Tue, 30 Dec 2025 15:01:04 +0100 Subject: [PATCH 02/14] Fixed typos and scope issues --- .../FT0Calibration/EventsPerBcCalibrator.h | 14 ++-- .../calibration/src/EventsPerBcCalibrator.cxx | 14 ++-- .../FT0EventsPerBcProcessor-Workflow.cxx | 68 ++++++++++++++----- 3 files changed, 63 insertions(+), 33 deletions(-) diff --git a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h index e96da70f0103a..a5d05fcd3f0cb 100644 --- a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h +++ b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h @@ -9,7 +9,6 @@ #include "DataFormatsFT0/SpectraInfoObject.h" #include "DetectorsCalibration/TimeSlotCalibration.h" #include "DetectorsCalibration/TimeSlot.h" -#include "DataFormatsFT0/BcEvents.h" namespace o2::ft0 { @@ -34,22 +33,19 @@ namespace o2::ft0 using TFType = o2::calibration::TFType; public: - EventsPerBcCalibrator() - { - setUpdateAtTheEndOfRunOnly(); - } + EventsPerBcCalibrator() = default; bool hasEnoughData(const Slot& slot) const final { return true; } void initOutput() final; void finalizeSlot(Slot& slot) final; Slot& emplaceNewSlot(bool front, TFType tstart, TFType tend) final; - const TH1F* getTvxPerBc() { return mTvxPerBc.get(); } - const CcdbObjectInfo* getTvxPerBcCcdbInfo() { return mTvxPerBcInfo.get(); } + const std::vector>& getTvxPerBc() { return mTvxPerBcs; } + std::vector>& getTvxPerBcCcdbInfo() { return mTvxPerBcInfos; } private: - std::unique_ptr mTvxPerBc; - std::unique_ptr mTvxPerBcInfo; + std::vector> mTvxPerBcs; + std::vector> mTvxPerBcInfos; }; } diff --git a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx index 718a1a96e71cc..4ef88ca9bec03 100644 --- a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx +++ b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx @@ -4,7 +4,7 @@ namespace o2::ft0 { void EventsPerBc::print() const { - + LOG(info) << entries << " entries"; } void EventsPerBc::fill(const gsl::span data) @@ -26,21 +26,21 @@ namespace o2::ft0 void EventsPerBcCalibrator::initOutput() final { - mTvxPerBc.reset(); - mTvxPerBcInfo.reset(); + mTvxPerBc.clear(); + mTvxPerBcInfo.clear(); } void EventsPerBcCalibrator::finalizeSlot(EventsPerBcCalibrator::Slot& slot) final { o2::ft0::EventsPerBc* data = slot.getContainer(); - mTvxPerBc = std::make_unique("TvxPerBc", "FT0 TVX per BC", o2::constants::lhc::LHCMaxBunches, 0, o2::constants::lhc::LHCMaxBunches - 1); + mTvxPerBcs.emplace_back(std::make_unique("TvxPerBc", "FT0 TVX per BC", o2::constants::lhc::LHCMaxBunches, 0, o2::constants::lhc::LHCMaxBunches - 1)); for(int bin = 0; bin < o2::constants::lhc::LHCMaxBunches; bin++) { - tvxsHist->fill(bin, data->mTvx[bin]); + mTvxPerBcs.back()->fill(bin, data->mTvx[bin]); } - auto clName = o2::utils::MemFileHelper::getClassName(*tvxsHist); + auto clName = o2::utils::MemFileHelper::getClassName(*mTvxPerBcs.back()); auto flName = o2::ccdb::CcdbApi::generateFileName(clName); std::map metaData; - mTvxPerBcInfo = std::make_unique("FT0/Calib/TvxPerBc", clName, flName, metaData, slot.getStarTimeMs(), slot.getEndTimeStampMS()); + mTvxPerBcInfos.emplace_back(std::make_unique("FT0/Calib/TvxPerBc", clName, flName, metaData, slot.getStarTimeMs(), slot.getEndTimeStampMS())); } EventsPerBcCalibrator::Slot& EventsPerBcCalibrator::emplaceNewSlot(bool front, TFType tstart, TFType tend) final diff --git a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx index 5a5fcdbc1b8e8..42d7aac693840 100644 --- a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx +++ b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx @@ -5,64 +5,98 @@ #include "Framework/DeviceSpec.h" #include "Framework/WorkflowSpec.h" #include "Framework/Task.h" +#include "DetectorsCalibration/Utils.h" #include "DataFormatsFT0/Digit.h" -#include "DataFormatsFT0/BcEvents.h" #include "FT0Calibration/EventsPerBcCalibrator.h" -namespace o2::ft0 + +namespace o2::calibration { class FT0EventsPerBcProcessor final : public o2::framework::Task { + public: void init(o2::framework::InitContext& ic) final { - mCalibrator = std::make_unique(); + mCalibrator = std::make_unique(); + if(ic.options().hasOption("slot-len-sec")) { + mSlotLenSec = ic.options().get("slot-len-sec"); + } + if(ic.options().hasOption("one-object-per-run")) { + mOneObjectPerRun = ic.options().get("one-object-per-run"); + } + + if(mOneObjectPerRun) { + mCalibrator->setUpdateAtTheEndOfRunOnly(); + } else { + mCalibrator->setSlotLengthInSeconds(mSlotLenSec); + } } - void run(o2::framework::ProcessContext& pc) final + void run(o2::framework::ProcessingContext& pc) final { auto digits = pc.inputs().get>("digits"); mCalibrator->process(digits); + if(mOneObjectPerRun == false) { + sendOutput(pc.outputs()); + } } void endOfStream(o2::framework::EndOfStreamContext& ec) final { - mCalibrator->chekSlotToFinalize(); + mCalibrator->checkSlotsToFinalize(); sendOutput(ec.outputs()); mCalibrator->initOutput(); } - void sendOutput(DataAllocator& output) + void sendOutput(o2::framework::DataAllocator& output) { - TH1F* tvxHist = mCalibrator->getTvxPerBc(); - CcdbObjectInfo* info = mCalibrator->getTvxPerBcCcdbInfo(); - auto image = o2::ccdb::CcdbApi::createObjectImage(tvxHist, info); - LOG(info) << "Sending object to CCDB"; - output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "EVENTS_PER_BC_INFO", 0}, *image.get()); - output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "EVENTS_PER_BC_INFO", 0}, info); + using o2::framework::Output; + + const auto& tvxHists = mCalibrator->getTvxPerBc(); + auto& infos = mCalibrator->getTvxPerBcCcdbInfo(); + for(int idx = 0; idx < tvxHists.size(); idx++){ + auto& info = infos[idx]; + const auto& payload = tvxHists[idx]; + + auto image = o2::ccdb::CcdbApi::createObjectImage(payload.get(), info.get()); + LOG(info) << "Sending object " << info->getPath() << "/" << info->getFileName() << " of size " << image->size() + << " bytes, valid for " << info->getStartValidityTimestamp() << " : " << info->getEndValidityTimestamp(); + output.snapshot(Output(o2::calibration::Utils::gDataOriginCDBPayload, "EVENTS_PER_BC_INFO", 0), *image.get()); + output.snapshot(Output(o2::calibration::Utils::gDataOriginCDBWrapper, "EVENTS_PER_BC_INFO", 0), *info.get()); + } } private: - std::unique_ptr mCalibrator; + std::unique_ptr mCalibrator; + bool mOneObjectPerRun; + uint32_t mSlotLenSec; }; } -WorkflowSpec defineDataProcessing(ConfigContext& const & cfgc) +namespace o2::framework +{ +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) { using namespace o2::framework; + using o2::calibration::FT0EventsPerBcProcessor; std::vector inputs; inputs.emplace_back("digits", "FT0", "DIGITSBC"); std::vector outputs; - outputs.emplace_back("eventsPerBcInfo", "FT0", "EVENTS_PER_BC_INFO") + outputs.emplace_back("eventsPerBcInfo", "FT0", "EVENTS_PER_BC_INFO"); DataProcessorSpec dataProcessorSpec{ "FT0EventsPerBcProcessor", inputs, outputs, - AlgorithmSpec(adaptFromTask()), - Options{} + AlgorithmSpec(adaptFromTask()), + Options{ + {"slot-len-sec", VariantType::UInt32, 3600u, "Time lenght of slot in seconds"}, + {"one-object-per-run", VariantType::Bool, false, "If true, then one calibration object is created per run"} + } }; WorkflowSpec workflow; workflow.emplace_back(dataProcessorSpec); return workflow; +} } \ No newline at end of file From eb6079755a45eabdef4f6c98bece9e8147927c89 Mon Sep 17 00:00:00 2001 From: wpierozak Date: Tue, 30 Dec 2025 21:06:50 +0100 Subject: [PATCH 03/14] Fixing bugs --- Detectors/FIT/FT0/calibration/CMakeLists.txt | 1 + .../FT0Calibration/EventsPerBcCalibrator.h | 2 + .../calibration/src/EventsPerBcCalibrator.cxx | 23 ++--- .../FT0EventsPerBcProcessor-Workflow.cxx | 88 ++----------------- .../calibration/workflow/FT0EventsPerBcSpec.h | 86 ++++++++++++++++++ 5 files changed, 106 insertions(+), 94 deletions(-) create mode 100644 Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h diff --git a/Detectors/FIT/FT0/calibration/CMakeLists.txt b/Detectors/FIT/FT0/calibration/CMakeLists.txt index 52acae2fbacc7..085ab566c868b 100644 --- a/Detectors/FIT/FT0/calibration/CMakeLists.txt +++ b/Detectors/FIT/FT0/calibration/CMakeLists.txt @@ -36,6 +36,7 @@ o2_add_library(FT0Calibration o2_add_executable(ft0-events-per-bc-processor COMPONENT_NAME calibration SOURCES workflow/FT0EventsPerBcProcessor-Workflow.cxx + src/EventsPerBcCalibrator.cxx PUBLIC_LINK_LIBRARIES O2::FT0Calibration ) diff --git a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h index a5d05fcd3f0cb..233568628c632 100644 --- a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h +++ b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h @@ -3,10 +3,12 @@ #include #include +#include #include "CommonDataFormat/FlatHisto2D.h" #include "CommonConstants/LHCConstants.h" #include "DataFormatsFT0/SpectraInfoObject.h" +#include "DataFormatsFT0/Digit.h" #include "DetectorsCalibration/TimeSlotCalibration.h" #include "DetectorsCalibration/TimeSlot.h" diff --git a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx index 4ef88ca9bec03..a259204f28652 100644 --- a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx +++ b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx @@ -1,4 +1,5 @@ #include "FT0Calibration/EventsPerBcCalibrator.h" +#include "CommonUtils/MemFileHelper.h" namespace o2::ft0 { @@ -9,9 +10,9 @@ namespace o2::ft0 void EventsPerBc::fill(const gsl::span data) { - for(const auto& digit: digits) { - double isVertex = digit.mTriggers.isVertex(); - mTvx[digits.mIntRecord.bc] += isVertex; + for(const auto& digit: data) { + double isVertex = digit.mTriggers.getVertex(); + mTvx[digit.mIntRecord.bc] += isVertex; entries += isVertex; } } @@ -21,29 +22,29 @@ namespace o2::ft0 for(int bc = 0; bc < o2::constants::lhc::LHCMaxBunches; bc++){ mTvx[bc] += prev->mTvx[bc]; } - entries += prev->mEntries; + entries += prev->entries; } - void EventsPerBcCalibrator::initOutput() final + void EventsPerBcCalibrator::initOutput() { - mTvxPerBc.clear(); - mTvxPerBcInfo.clear(); + mTvxPerBcs.clear(); + mTvxPerBcInfos.clear(); } - void EventsPerBcCalibrator::finalizeSlot(EventsPerBcCalibrator::Slot& slot) final + void EventsPerBcCalibrator::finalizeSlot(EventsPerBcCalibrator::Slot& slot) { o2::ft0::EventsPerBc* data = slot.getContainer(); mTvxPerBcs.emplace_back(std::make_unique("TvxPerBc", "FT0 TVX per BC", o2::constants::lhc::LHCMaxBunches, 0, o2::constants::lhc::LHCMaxBunches - 1)); for(int bin = 0; bin < o2::constants::lhc::LHCMaxBunches; bin++) { - mTvxPerBcs.back()->fill(bin, data->mTvx[bin]); + mTvxPerBcs.back()->Fill(bin, data->mTvx[bin]); } auto clName = o2::utils::MemFileHelper::getClassName(*mTvxPerBcs.back()); auto flName = o2::ccdb::CcdbApi::generateFileName(clName); std::map metaData; - mTvxPerBcInfos.emplace_back(std::make_unique("FT0/Calib/TvxPerBc", clName, flName, metaData, slot.getStarTimeMs(), slot.getEndTimeStampMS())); + mTvxPerBcInfos.emplace_back(std::make_unique("FT0/Calib/TvxPerBc", clName, flName, metaData, slot.getStartTimeMS(), slot.getEndTimeMS())); } - EventsPerBcCalibrator::Slot& EventsPerBcCalibrator::emplaceNewSlot(bool front, TFType tstart, TFType tend) final + EventsPerBcCalibrator::Slot& EventsPerBcCalibrator::emplaceNewSlot(bool front, TFType tstart, TFType tend) { auto& cont = getSlots(); auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend); diff --git a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx index 42d7aac693840..c02847d922eea 100644 --- a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx +++ b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx @@ -1,102 +1,24 @@ -#include "Framework/runDataProcessing.h" -#include "CommonUtils/ConfigurableParam.h" -#include "Framework/ConfigParamSpec.h" -#include -#include "Framework/DeviceSpec.h" -#include "Framework/WorkflowSpec.h" -#include "Framework/Task.h" -#include "DetectorsCalibration/Utils.h" - -#include "DataFormatsFT0/Digit.h" -#include "FT0Calibration/EventsPerBcCalibrator.h" - - -namespace o2::calibration -{ - class FT0EventsPerBcProcessor final : public o2::framework::Task - { - public: - void init(o2::framework::InitContext& ic) final - { - mCalibrator = std::make_unique(); - if(ic.options().hasOption("slot-len-sec")) { - mSlotLenSec = ic.options().get("slot-len-sec"); - } - if(ic.options().hasOption("one-object-per-run")) { - mOneObjectPerRun = ic.options().get("one-object-per-run"); - } - - if(mOneObjectPerRun) { - mCalibrator->setUpdateAtTheEndOfRunOnly(); - } else { - mCalibrator->setSlotLengthInSeconds(mSlotLenSec); - } - } - - void run(o2::framework::ProcessingContext& pc) final - { - auto digits = pc.inputs().get>("digits"); - mCalibrator->process(digits); - if(mOneObjectPerRun == false) { - sendOutput(pc.outputs()); - } - } - - void endOfStream(o2::framework::EndOfStreamContext& ec) final - { - mCalibrator->checkSlotsToFinalize(); - sendOutput(ec.outputs()); - mCalibrator->initOutput(); - } - - void sendOutput(o2::framework::DataAllocator& output) - { - using o2::framework::Output; - - const auto& tvxHists = mCalibrator->getTvxPerBc(); - auto& infos = mCalibrator->getTvxPerBcCcdbInfo(); - for(int idx = 0; idx < tvxHists.size(); idx++){ - auto& info = infos[idx]; - const auto& payload = tvxHists[idx]; - - auto image = o2::ccdb::CcdbApi::createObjectImage(payload.get(), info.get()); - LOG(info) << "Sending object " << info->getPath() << "/" << info->getFileName() << " of size " << image->size() - << " bytes, valid for " << info->getStartValidityTimestamp() << " : " << info->getEndValidityTimestamp(); - output.snapshot(Output(o2::calibration::Utils::gDataOriginCDBPayload, "EVENTS_PER_BC_INFO", 0), *image.get()); - output.snapshot(Output(o2::calibration::Utils::gDataOriginCDBWrapper, "EVENTS_PER_BC_INFO", 0), *info.get()); - } - } - - private: - std::unique_ptr mCalibrator; - bool mOneObjectPerRun; - uint32_t mSlotLenSec; - }; -} - -namespace o2::framework -{ -WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) +#include "FT0EventsPerBcSpec.h" +o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext const& cfgc) { using namespace o2::framework; using o2::calibration::FT0EventsPerBcProcessor; std::vector inputs; inputs.emplace_back("digits", "FT0", "DIGITSBC"); std::vector outputs; - outputs.emplace_back("eventsPerBcInfo", "FT0", "EVENTS_PER_BC_INFO"); + outputs.emplace_back(ConcreteDataTypeMatcher{"FT0", "EventsPerBc"}, Lifetime::Sporadic); DataProcessorSpec dataProcessorSpec{ "FT0EventsPerBcProcessor", inputs, outputs, AlgorithmSpec(adaptFromTask()), Options{ - {"slot-len-sec", VariantType::UInt32, 3600u, "Time lenght of slot in seconds"}, - {"one-object-per-run", VariantType::Bool, false, "If true, then one calibration object is created per run"} + {"slot-len-sec", VariantType::UInt32, 3600u, {"Time lenght of slot in seconds"}}, + {"one-object-per-run", VariantType::Bool, false, {"If true, then one calibration object is created per run"}} } }; WorkflowSpec workflow; workflow.emplace_back(dataProcessorSpec); return workflow; -} } \ No newline at end of file diff --git a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h new file mode 100644 index 0000000000000..b19e6cc174099 --- /dev/null +++ b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h @@ -0,0 +1,86 @@ + +#ifndef O2_CALIBRATION_FT0_EVENTS_PER_BC_CALIBRATOR_H +#define O2_CALIBRATION_FT0_EVENTS_PER_BC_CALIBRATOR_H + +#include "Framework/runDataProcessing.h" +#include "CommonUtils/ConfigurableParam.h" +#include "Framework/ConfigParamSpec.h" +#include +#include "Framework/DeviceSpec.h" +#include "Framework/WorkflowSpec.h" +#include "Framework/Task.h" +#include "DetectorsCalibration/Utils.h" + +#include "DataFormatsFT0/Digit.h" +#include "FT0Calibration/EventsPerBcCalibrator.h" + + +namespace o2::calibration +{ + class FT0EventsPerBcProcessor final : public o2::framework::Task + { + public: + FT0EventsPerBcProcessor() = default; + + void init(o2::framework::InitContext& ic) final + { + mCalibrator = std::make_unique(); + if(ic.options().hasOption("slot-len-sec")) { + mSlotLenSec = ic.options().get("slot-len-sec"); + } + if(ic.options().hasOption("one-object-per-run")) { + mOneObjectPerRun = ic.options().get("one-object-per-run"); + } + + if(mOneObjectPerRun) { + mCalibrator->setUpdateAtTheEndOfRunOnly(); + } else { + mCalibrator->setSlotLengthInSeconds(mSlotLenSec); + } + } + + void run(o2::framework::ProcessingContext& pc) final + { + auto digits = pc.inputs().get>("digits"); + mCalibrator->process(digits); + if(mOneObjectPerRun == false) { + sendOutput(pc.outputs()); + } + } + + void endOfStream(o2::framework::EndOfStreamContext& ec) final + { + mCalibrator->checkSlotsToFinalize(); + sendOutput(ec.outputs()); + mCalibrator->initOutput(); + } + + void sendOutput(o2::framework::DataAllocator& output) + { + using o2::framework::Output; + + const auto& tvxHists = mCalibrator->getTvxPerBc(); + auto& infos = mCalibrator->getTvxPerBcCcdbInfo(); + for(int idx = 0; idx < tvxHists.size(); idx++){ + auto& info = infos[idx]; + const auto& payload = tvxHists[idx]; + + auto image = o2::ccdb::CcdbApi::createObjectImage(payload.get(), info.get()); + LOG(info) << "Sending object " << info->getPath() << "/" << info->getFileName() << " of size " << image->size() + << " bytes, valid for " << info->getStartValidityTimestamp() << " : " << info->getEndValidityTimestamp(); + output.snapshot(Output{o2::header::gDataOriginFT0, "EventsPerBc", idx}, *image.get()); + output.snapshot(Output{o2::header::gDataOriginFT0, "EventsPerBc", idx}, *info.get()); + } + + if(tvxHists.size()) { + mCalibrator->initOutput(); + } + } + + private: + std::unique_ptr mCalibrator; + bool mOneObjectPerRun; + uint32_t mSlotLenSec; + }; +} +#endif \ No newline at end of file From aec692a9429a296f2ce101cb9571382be3a0a039 Mon Sep 17 00:00:00 2001 From: wpierozak Date: Mon, 5 Jan 2026 11:02:42 +0100 Subject: [PATCH 04/14] FT0: Updated CMakeLists for calibration --- Detectors/FIT/FT0/calibration/CMakeLists.txt | 76 +++++++++++-------- .../FT0Calibration/EventsPerBcCalibrator.h | 4 + 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/Detectors/FIT/FT0/calibration/CMakeLists.txt b/Detectors/FIT/FT0/calibration/CMakeLists.txt index 085ab566c868b..ec0c1d42f5eea 100644 --- a/Detectors/FIT/FT0/calibration/CMakeLists.txt +++ b/Detectors/FIT/FT0/calibration/CMakeLists.txt @@ -10,34 +10,50 @@ # or submit itself to any jurisdiction. o2_add_library(FT0Calibration - SOURCES - src/FT0TimeOffsetSlotContainer.cxx - PUBLIC_LINK_LIBRARIES - O2::DataFormatsFT0 - O2::CommonDataFormat - O2::DetectorsCalibration - ) - o2_target_root_dictionary(FT0Calibration - HEADERS - include/FT0Calibration/FT0TimeOffsetSlotContainer.h - ) - o2_add_executable(ft0-time-offset-calib - COMPONENT_NAME calibration - SOURCES workflow/FT0TimeOffsetCalibration-Workflow.cxx - PUBLIC_LINK_LIBRARIES - O2::FT0Calibration O2::FITCalibration - ) - o2_add_executable(ft0-time-spectra-processor - COMPONENT_NAME calibration - SOURCES workflow/FT0TimeSpectraProcessor-Workflow.cxx - PUBLIC_LINK_LIBRARIES - O2::FT0Calibration - ) - o2_add_executable(ft0-events-per-bc-processor - COMPONENT_NAME calibration - SOURCES workflow/FT0EventsPerBcProcessor-Workflow.cxx - src/EventsPerBcCalibrator.cxx - PUBLIC_LINK_LIBRARIES - O2::FT0Calibration - ) + SOURCES + src/FT0TimeOffsetSlotContainer.cxx + src/EventsPerBcCalibrator.cxx + PUBLIC_LINK_LIBRARIES + O2::DetectorsCalibration + O2::Framework + O2::CommonUtils + Microsoft.GSL::GSL + O2::DataFormatsFT0 + O2::CommonDataFormat + O2::Steer + O2::CCDB + ROOT::Minuit + ) + +o2_target_root_dictionary(FT0Calibration + HEADERS + include/FT0Calibration/FT0TimeOffsetSlotContainer.h + include/FT0Calibration/EventsPerBcCalibrator.h + ) + +o2_add_executable(ft0-time-offset-calib + COMPONENT_NAME calibration + SOURCES + workflow/FT0TimeOffsetCalibration-Workflow.cxx + PUBLIC_LINK_LIBRARIES + O2::FT0Calibration O2::FITCalibration + ) + +o2_add_executable(ft0-time-spectra-processor + COMPONENT_NAME calibration + SOURCES + workflow/FT0TimeSpectraProcessor-Workflow.cxx + PUBLIC_LINK_LIBRARIES + O2::FT0Calibration + ) + +o2_add_executable(ft0-events-per-bc-processor + COMPONENT_NAME calibration + SOURCES + workflow/FT0EventsPerBcProcessor-Workflow.cxx + PUBLIC_LINK_LIBRARIES + O2::FT0Calibration + O2::Framework + O2::CCDB +) \ No newline at end of file diff --git a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h index 233568628c632..15fc7f4fa9d91 100644 --- a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h +++ b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h @@ -27,6 +27,8 @@ namespace o2::ft0 size_t entries{0}; long startTimeStamp{0}; long stopTimeStamp{0}; + + ClassDefNV(EventsPerBc, 1); }; class EventsPerBcCalibrator final : public o2::calibration::TimeSlotCalibration @@ -48,6 +50,8 @@ namespace o2::ft0 private: std::vector> mTvxPerBcs; std::vector> mTvxPerBcInfos; + + ClassDefOverride(EventsPerBcCalibrator, 1); }; } From f49611cced4c7078639293cc6a059a68eb38f8cc Mon Sep 17 00:00:00 2001 From: wpierozak Date: Mon, 5 Jan 2026 11:26:38 +0100 Subject: [PATCH 05/14] FT0: Added missing entry in FT0CalibrationLinkDef.h --- Detectors/FIT/FT0/calibration/CMakeLists.txt | 1 + .../calibration/include/FT0Calibration/EventsPerBcCalibrator.h | 2 ++ Detectors/FIT/FT0/calibration/src/FT0CalibrationLinkDef.h | 1 + 3 files changed, 4 insertions(+) diff --git a/Detectors/FIT/FT0/calibration/CMakeLists.txt b/Detectors/FIT/FT0/calibration/CMakeLists.txt index ec0c1d42f5eea..75cf762dad991 100644 --- a/Detectors/FIT/FT0/calibration/CMakeLists.txt +++ b/Detectors/FIT/FT0/calibration/CMakeLists.txt @@ -23,6 +23,7 @@ o2_add_library(FT0Calibration O2::Steer O2::CCDB ROOT::Minuit + ROOT::Hist ) o2_target_root_dictionary(FT0Calibration diff --git a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h index 15fc7f4fa9d91..07c6d2d03d2f4 100644 --- a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h +++ b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h @@ -11,6 +11,8 @@ #include "DataFormatsFT0/Digit.h" #include "DetectorsCalibration/TimeSlotCalibration.h" #include "DetectorsCalibration/TimeSlot.h" +#include "TH1F.h" +#include "Rtypes.h" namespace o2::ft0 { diff --git a/Detectors/FIT/FT0/calibration/src/FT0CalibrationLinkDef.h b/Detectors/FIT/FT0/calibration/src/FT0CalibrationLinkDef.h index 49f72e8cbdfff..7c48e20ec7151 100644 --- a/Detectors/FIT/FT0/calibration/src/FT0CalibrationLinkDef.h +++ b/Detectors/FIT/FT0/calibration/src/FT0CalibrationLinkDef.h @@ -16,6 +16,7 @@ #pragma link off all functions; #pragma link C++ class o2::ft0::FT0TimeOffsetSlotContainer + ; +#pragma link C++ class o2::calibration::EventsPerBcCalibrator + ; #pragma link C++ class o2::calibration::TimeSlot < o2::ft0::FT0TimeOffsetSlotContainer>; #pragma link C++ class o2::calibration::TimeSlotCalibration < o2::ft0::FT0TimeOffsetSlotContainer>; From 00be70b31127b9f19ad9b50a17ef7a588497ff68 Mon Sep 17 00:00:00 2001 From: wpierozak Date: Mon, 5 Jan 2026 16:21:22 +0100 Subject: [PATCH 06/14] FT0 calibration: fixed ROOT directory compilation, fixed CCDB output --- .../include/FT0Calibration/EventsPerBcCalibrator.h | 9 +++++---- .../FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx | 9 +++++++++ .../FIT/FT0/calibration/src/FT0CalibrationLinkDef.h | 5 +++-- .../workflow/FT0EventsPerBcProcessor-Workflow.cxx | 3 ++- .../FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h | 8 +++++--- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h index 07c6d2d03d2f4..5f9830f1701cc 100644 --- a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h +++ b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h @@ -41,10 +41,10 @@ namespace o2::ft0 public: EventsPerBcCalibrator() = default; - bool hasEnoughData(const Slot& slot) const final { return true; } - void initOutput() final; - void finalizeSlot(Slot& slot) final; - Slot& emplaceNewSlot(bool front, TFType tstart, TFType tend) final; + bool hasEnoughData(const Slot& slot) const override; + void initOutput() override; + void finalizeSlot(Slot& slot) override; + Slot& emplaceNewSlot(bool front, TFType tstart, TFType tend) override; const std::vector>& getTvxPerBc() { return mTvxPerBcs; } std::vector>& getTvxPerBcCcdbInfo() { return mTvxPerBcInfos; } @@ -52,6 +52,7 @@ namespace o2::ft0 private: std::vector> mTvxPerBcs; std::vector> mTvxPerBcInfos; + uint32_t mMinNumberOfEntries{1000}; ClassDefOverride(EventsPerBcCalibrator, 1); }; diff --git a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx index a259204f28652..2d860f59aaf7d 100644 --- a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx +++ b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx @@ -10,11 +10,13 @@ namespace o2::ft0 void EventsPerBc::fill(const gsl::span data) { + size_t oldEntries = entries; for(const auto& digit: data) { double isVertex = digit.mTriggers.getVertex(); mTvx[digit.mIntRecord.bc] += isVertex; entries += isVertex; } + LOG(debug) << "Container is filled with " << entries - oldEntries << " new VTX events"; } void EventsPerBc::merge(const EventsPerBc* prev) @@ -31,8 +33,14 @@ namespace o2::ft0 mTvxPerBcInfos.clear(); } + bool EventsPerBcCalibrator::hasEnoughData(const EventsPerBcCalibrator::Slot& slot) const + { + return slot.getContainer()->entries > mMinNumberOfEntries; + } + void EventsPerBcCalibrator::finalizeSlot(EventsPerBcCalibrator::Slot& slot) { + LOG(info) << "Finializing slot from " << slot.getStartTimeMS() << " to " << slot.getEndTimeMS(); o2::ft0::EventsPerBc* data = slot.getContainer(); mTvxPerBcs.emplace_back(std::make_unique("TvxPerBc", "FT0 TVX per BC", o2::constants::lhc::LHCMaxBunches, 0, o2::constants::lhc::LHCMaxBunches - 1)); for(int bin = 0; bin < o2::constants::lhc::LHCMaxBunches; bin++) { @@ -42,6 +50,7 @@ namespace o2::ft0 auto flName = o2::ccdb::CcdbApi::generateFileName(clName); std::map metaData; mTvxPerBcInfos.emplace_back(std::make_unique("FT0/Calib/TvxPerBc", clName, flName, metaData, slot.getStartTimeMS(), slot.getEndTimeMS())); + LOG(info) << "Created new calibration object. Current number of objects: " << mTvxPerBcs.size(); } EventsPerBcCalibrator::Slot& EventsPerBcCalibrator::emplaceNewSlot(bool front, TFType tstart, TFType tend) diff --git a/Detectors/FIT/FT0/calibration/src/FT0CalibrationLinkDef.h b/Detectors/FIT/FT0/calibration/src/FT0CalibrationLinkDef.h index 7c48e20ec7151..6a12994ae77d9 100644 --- a/Detectors/FIT/FT0/calibration/src/FT0CalibrationLinkDef.h +++ b/Detectors/FIT/FT0/calibration/src/FT0CalibrationLinkDef.h @@ -16,8 +16,9 @@ #pragma link off all functions; #pragma link C++ class o2::ft0::FT0TimeOffsetSlotContainer + ; -#pragma link C++ class o2::calibration::EventsPerBcCalibrator + ; +#pragma link C++ class o2::ft0::EventsPerBcCalibrator + ; #pragma link C++ class o2::calibration::TimeSlot < o2::ft0::FT0TimeOffsetSlotContainer>; #pragma link C++ class o2::calibration::TimeSlotCalibration < o2::ft0::FT0TimeOffsetSlotContainer>; - +#pragma link C++ class o2::calibration::TimeSlot < o2::ft0::EventsPerBc> + ; +#pragma link C++ class o2::calibration::TimeSlotCalibration < o2::ft0::EventsPerBc> + ; #endif diff --git a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx index c02847d922eea..6ce85438d597c 100644 --- a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx +++ b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx @@ -6,7 +6,8 @@ o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext co std::vector inputs; inputs.emplace_back("digits", "FT0", "DIGITSBC"); std::vector outputs; - outputs.emplace_back(ConcreteDataTypeMatcher{"FT0", "EventsPerBc"}, Lifetime::Sporadic); + outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "EventsPerBc"}, Lifetime::Sporadic); + outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "EventsPerBc"}, Lifetime::Sporadic); DataProcessorSpec dataProcessorSpec{ "FT0EventsPerBcProcessor", inputs, diff --git a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h index b19e6cc174099..43a4a2b6538a1 100644 --- a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h +++ b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h @@ -42,6 +42,9 @@ namespace o2::calibration void run(o2::framework::ProcessingContext& pc) final { auto digits = pc.inputs().get>("digits"); + if(digits.size() == 0) { + return; + } mCalibrator->process(digits); if(mOneObjectPerRun == false) { sendOutput(pc.outputs()); @@ -58,7 +61,6 @@ namespace o2::calibration void sendOutput(o2::framework::DataAllocator& output) { using o2::framework::Output; - const auto& tvxHists = mCalibrator->getTvxPerBc(); auto& infos = mCalibrator->getTvxPerBcCcdbInfo(); for(int idx = 0; idx < tvxHists.size(); idx++){ @@ -68,8 +70,8 @@ namespace o2::calibration auto image = o2::ccdb::CcdbApi::createObjectImage(payload.get(), info.get()); LOG(info) << "Sending object " << info->getPath() << "/" << info->getFileName() << " of size " << image->size() << " bytes, valid for " << info->getStartValidityTimestamp() << " : " << info->getEndValidityTimestamp(); - output.snapshot(Output{o2::header::gDataOriginFT0, "EventsPerBc", idx}, *image.get()); - output.snapshot(Output{o2::header::gDataOriginFT0, "EventsPerBc", idx}, *info.get()); + output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "EventsPerBc", idx}, *image.get()); + output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "EventsPerBc", idx}, *info.get()); } if(tvxHists.size()) { From 675464bf853dc713e96503c3dd24ac3a0462d5ec Mon Sep 17 00:00:00 2001 From: wpierozak Date: Wed, 7 Jan 2026 14:28:49 +0100 Subject: [PATCH 07/14] FT0: refined logs in EventsPerBc calibration, fixed setting TF info in run method --- .../FT0Calibration/EventsPerBcCalibrator.h | 16 ++++++--- .../calibration/src/EventsPerBcCalibrator.cxx | 17 ++++++++-- .../FT0EventsPerBcProcessor-Workflow.cxx | 9 +++-- .../calibration/workflow/FT0EventsPerBcSpec.h | 34 ++++++++++++++++--- 4 files changed, 63 insertions(+), 13 deletions(-) diff --git a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h index 5f9830f1701cc..487ed5d7dc228 100644 --- a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h +++ b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h @@ -3,6 +3,7 @@ #include #include +#include #include #include "CommonDataFormat/FlatHisto2D.h" @@ -11,6 +12,7 @@ #include "DataFormatsFT0/Digit.h" #include "DetectorsCalibration/TimeSlotCalibration.h" #include "DetectorsCalibration/TimeSlot.h" +#include "CommonDataFormat/TFIDInfo.h" #include "TH1F.h" #include "Rtypes.h" @@ -18,13 +20,16 @@ namespace o2::ft0 { struct EventsPerBc { - EventsPerBc() = default; + EventsPerBc(int32_t minAmplitudeSideA, int32_t minAmplitudeSideC): mMinAmplitudeSideA(minAmplitudeSideA), mMinAmplitudeSideC(minAmplitudeSideC) {} size_t getEntries() const { return entries; } void print() const; - void fill(const gsl::span data); + void fill(const o2::dataformats::TFIDInfo& ti, const gsl::span data); void merge(const EventsPerBc* prev); + const int32_t mMinAmplitudeSideA; + const int32_t mMinAmplitudeSideC; + std::array mTvx{0.0}; size_t entries{0}; long startTimeStamp{0}; @@ -39,7 +44,7 @@ namespace o2::ft0 using TFType = o2::calibration::TFType; public: - EventsPerBcCalibrator() = default; + EventsPerBcCalibrator(uint32_t minNumberOfEntries, int32_t minAmplitudeSideA, int32_t minAmplitudeSideC); bool hasEnoughData(const Slot& slot) const override; void initOutput() override; @@ -50,9 +55,12 @@ namespace o2::ft0 std::vector>& getTvxPerBcCcdbInfo() { return mTvxPerBcInfos; } private: + const uint32_t mMinNumberOfEntries; + const int32_t mMinAmplitudeSideA; + const int32_t mMinAmplitudeSideC; + std::vector> mTvxPerBcs; std::vector> mTvxPerBcInfos; - uint32_t mMinNumberOfEntries{1000}; ClassDefOverride(EventsPerBcCalibrator, 1); }; diff --git a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx index 2d860f59aaf7d..2c3f840cd586d 100644 --- a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx +++ b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx @@ -8,11 +8,14 @@ namespace o2::ft0 LOG(info) << entries << " entries"; } - void EventsPerBc::fill(const gsl::span data) + void EventsPerBc::fill(const o2::dataformats::TFIDInfo& ti, const gsl::span data) { size_t oldEntries = entries; for(const auto& digit: data) { double isVertex = digit.mTriggers.getVertex(); + if(digit.mTriggers.getAmplA() < mMinAmplitudeSideA || digit.mTriggers.getAmplC() < mMinAmplitudeSideC) { + continue; + } mTvx[digit.mIntRecord.bc] += isVertex; entries += isVertex; } @@ -33,6 +36,14 @@ namespace o2::ft0 mTvxPerBcInfos.clear(); } + + EventsPerBcCalibrator::EventsPerBcCalibrator(uint32_t minNumberOfEntries, int32_t minAmplitudeSideA, int32_t minAmplitudeSideC): mMinNumberOfEntries(minNumberOfEntries), mMinAmplitudeSideA(minAmplitudeSideA), mMinAmplitudeSideC(minAmplitudeSideC) + { + LOG(info) << "Defined threshold for number of entires per slot: " << mMinNumberOfEntries; + LOG(info) << "Defined threshold for side A amplitude for event: " << mMinAmplitudeSideA; + LOG(info) << "Defined threshold for side C amplitude for event: " << mMinAmplitudeSideC; + } + bool EventsPerBcCalibrator::hasEnoughData(const EventsPerBcCalibrator::Slot& slot) const { return slot.getContainer()->entries > mMinNumberOfEntries; @@ -40,7 +51,7 @@ namespace o2::ft0 void EventsPerBcCalibrator::finalizeSlot(EventsPerBcCalibrator::Slot& slot) { - LOG(info) << "Finializing slot from " << slot.getStartTimeMS() << " to " << slot.getEndTimeMS(); + LOG(info) << "Finalizing slot from " << slot.getStartTimeMS() << " to " << slot.getEndTimeMS(); o2::ft0::EventsPerBc* data = slot.getContainer(); mTvxPerBcs.emplace_back(std::make_unique("TvxPerBc", "FT0 TVX per BC", o2::constants::lhc::LHCMaxBunches, 0, o2::constants::lhc::LHCMaxBunches - 1)); for(int bin = 0; bin < o2::constants::lhc::LHCMaxBunches; bin++) { @@ -57,7 +68,7 @@ namespace o2::ft0 { auto& cont = getSlots(); auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend); - slot.setContainer(std::make_unique()); + slot.setContainer(std::make_unique(mMinAmplitudeSideA, mMinAmplitudeSideC)); return slot; } } \ No newline at end of file diff --git a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx index 6ce85438d597c..817fe5b3966de 100644 --- a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx +++ b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx @@ -1,4 +1,5 @@ #include "FT0EventsPerBcSpec.h" +#include o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext const& cfgc) { using namespace o2::framework; @@ -14,8 +15,12 @@ o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext co outputs, AlgorithmSpec(adaptFromTask()), Options{ - {"slot-len-sec", VariantType::UInt32, 3600u, {"Time lenght of slot in seconds"}}, - {"one-object-per-run", VariantType::Bool, false, {"If true, then one calibration object is created per run"}} + {"slot-len-sec", VariantType::UInt32, 3600u, {"Duration of each slot in seconds"}}, + {"slot-len-tf", VariantType::UInt32, 0u, {"Slot length in Time Frames (TFs)"}}, + {"one-object-per-run", VariantType::Bool, false, {"If set, workflow creates only one calibration object per run"}}, + {"min-entries-number", VariantType::UInt32, 0u, {"Minimum number of entries required for a slot to be valid"}}, + {"min-ampl-side-a", VariantType::Int, std::numeric_limits::min(), {"Amplitude threshold for Side A events"}}, + {"min-ampl-side-c", VariantType::Int, std::numeric_limits::min(), {"Amplitude threshold for Side C events"}} } }; diff --git a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h index 43a4a2b6538a1..c3a2b9101c46d 100644 --- a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h +++ b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h @@ -24,24 +24,45 @@ namespace o2::calibration void init(o2::framework::InitContext& ic) final { - mCalibrator = std::make_unique(); if(ic.options().hasOption("slot-len-sec")) { mSlotLenSec = ic.options().get("slot-len-sec"); } if(ic.options().hasOption("one-object-per-run")) { mOneObjectPerRun = ic.options().get("one-object-per-run"); } + if(ic.options().hasOption("slot-len-tf")) { + mSlotLen = ic.options().get("slot-len-tf"); + } + if(ic.options().hasOption("min-entries-number")) { + mMinNumberOfEntries = ic.options().get("min-entries-number"); + } + if(ic.options().hasOption("min-ampl-side-a")) { + mMinAmplitudeSideA = ic.options().get("min-ampl-side-a"); + } + if(ic.options().hasOption("min-ampl-side-c")) { + mMinAmplitudeSideC = ic.options().get("min-ampl-side-c"); + } + + mCalibrator = std::make_unique(mMinNumberOfEntries, mMinAmplitudeSideA, mMinAmplitudeSideC); if(mOneObjectPerRun) { + LOG(info) << "Only one object will be created at the end of run"; mCalibrator->setUpdateAtTheEndOfRunOnly(); - } else { + } + if (mOneObjectPerRun == false && mSlotLen == 0){ + LOG(info) << "Defined slot interval to " << mSlotLenSec << " seconds"; mCalibrator->setSlotLengthInSeconds(mSlotLenSec); + } + if (mOneObjectPerRun == false && mSlotLen != 0) { + LOG(info) << "Defined slot interval to " << mSlotLen << " TFS"; + mCalibrator->setSlotLength(mSlotLen); } } void run(o2::framework::ProcessingContext& pc) final { auto digits = pc.inputs().get>("digits"); + o2::base::TFIDInfoHelper::fillTFIDInfo(pc, mCalibrator->getCurrentTFInfo()); if(digits.size() == 0) { return; } @@ -51,8 +72,9 @@ namespace o2::calibration } } - void endOfStream(o2::framework::EndOfStreamContext& ec) final + void endOfStream(o2::framework::EndOfStreamContext& ec) final { + LOG(info) << "Received end-of-stream, checking for slot to finalize..."; mCalibrator->checkSlotsToFinalize(); sendOutput(ec.outputs()); mCalibrator->initOutput(); @@ -63,7 +85,7 @@ namespace o2::calibration using o2::framework::Output; const auto& tvxHists = mCalibrator->getTvxPerBc(); auto& infos = mCalibrator->getTvxPerBcCcdbInfo(); - for(int idx = 0; idx < tvxHists.size(); idx++){ + for(unsigned int idx = 0; idx < tvxHists.size(); idx++){ auto& info = infos[idx]; const auto& payload = tvxHists[idx]; @@ -83,6 +105,10 @@ namespace o2::calibration std::unique_ptr mCalibrator; bool mOneObjectPerRun; uint32_t mSlotLenSec; + o2::calibration::TFType mSlotLen; + uint32_t mMinNumberOfEntries; + int32_t mMinAmplitudeSideA; + int32_t mMinAmplitudeSideC; }; } #endif \ No newline at end of file From 986a12bbb9353f90b4c483db308581d19ba980e5 Mon Sep 17 00:00:00 2001 From: wpierozak Date: Mon, 12 Jan 2026 16:41:18 +0100 Subject: [PATCH 08/14] FT0: executed clang-format --- .../FT0Calibration/EventsPerBcCalibrator.h | 54 ++++++------ .../calibration/src/EventsPerBcCalibrator.cxx | 19 ++-- .../FT0EventsPerBcProcessor-Workflow.cxx | 24 +++--- .../calibration/workflow/FT0EventsPerBcSpec.h | 86 +++++++++---------- 4 files changed, 90 insertions(+), 93 deletions(-) diff --git a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h index 487ed5d7dc228..fdc2c85992b12 100644 --- a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h +++ b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h @@ -20,22 +20,22 @@ namespace o2::ft0 { struct EventsPerBc { - EventsPerBc(int32_t minAmplitudeSideA, int32_t minAmplitudeSideC): mMinAmplitudeSideA(minAmplitudeSideA), mMinAmplitudeSideC(minAmplitudeSideC) {} - - size_t getEntries() const { return entries; } - void print() const; - void fill(const o2::dataformats::TFIDInfo& ti, const gsl::span data); - void merge(const EventsPerBc* prev); + EventsPerBc(int32_t minAmplitudeSideA, int32_t minAmplitudeSideC) : mMinAmplitudeSideA(minAmplitudeSideA), mMinAmplitudeSideC(minAmplitudeSideC) {} - const int32_t mMinAmplitudeSideA; - const int32_t mMinAmplitudeSideC; + size_t getEntries() const { return entries; } + void print() const; + void fill(const o2::dataformats::TFIDInfo& ti, const gsl::span data); + void merge(const EventsPerBc* prev); - std::array mTvx{0.0}; - size_t entries{0}; - long startTimeStamp{0}; - long stopTimeStamp{0}; + const int32_t mMinAmplitudeSideA; + const int32_t mMinAmplitudeSideC; - ClassDefNV(EventsPerBc, 1); + std::array mTvx{0.0}; + size_t entries{0}; + long startTimeStamp{0}; + long stopTimeStamp{0}; + + ClassDefNV(EventsPerBc, 1); }; class EventsPerBcCalibrator final : public o2::calibration::TimeSlotCalibration @@ -44,25 +44,25 @@ namespace o2::ft0 using TFType = o2::calibration::TFType; public: - EventsPerBcCalibrator(uint32_t minNumberOfEntries, int32_t minAmplitudeSideA, int32_t minAmplitudeSideC); - - bool hasEnoughData(const Slot& slot) const override; - void initOutput() override; - void finalizeSlot(Slot& slot) override; - Slot& emplaceNewSlot(bool front, TFType tstart, TFType tend) override; + EventsPerBcCalibrator(uint32_t minNumberOfEntries, int32_t minAmplitudeSideA, int32_t minAmplitudeSideC); + + bool hasEnoughData(const Slot& slot) const override; + void initOutput() override; + void finalizeSlot(Slot& slot) override; + Slot& emplaceNewSlot(bool front, TFType tstart, TFType tend) override; - const std::vector>& getTvxPerBc() { return mTvxPerBcs; } - std::vector>& getTvxPerBcCcdbInfo() { return mTvxPerBcInfos; } + const std::vector>& getTvxPerBc() { return mTvxPerBcs; } + std::vector>& getTvxPerBcCcdbInfo() { return mTvxPerBcInfos; } private: - const uint32_t mMinNumberOfEntries; - const int32_t mMinAmplitudeSideA; - const int32_t mMinAmplitudeSideC; + const uint32_t mMinNumberOfEntries; + const int32_t mMinAmplitudeSideA; + const int32_t mMinAmplitudeSideC; - std::vector> mTvxPerBcs; - std::vector> mTvxPerBcInfos; + std::vector> mTvxPerBcs; + std::vector> mTvxPerBcInfos; - ClassDefOverride(EventsPerBcCalibrator, 1); + ClassDefOverride(EventsPerBcCalibrator, 1); }; } diff --git a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx index 2c3f840cd586d..0e69a090b0c0e 100644 --- a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx +++ b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx @@ -13,8 +13,8 @@ namespace o2::ft0 size_t oldEntries = entries; for(const auto& digit: data) { double isVertex = digit.mTriggers.getVertex(); - if(digit.mTriggers.getAmplA() < mMinAmplitudeSideA || digit.mTriggers.getAmplC() < mMinAmplitudeSideC) { - continue; + if (digit.mTriggers.getAmplA() < mMinAmplitudeSideA || digit.mTriggers.getAmplC() < mMinAmplitudeSideC) { + continue; } mTvx[digit.mIntRecord.bc] += isVertex; entries += isVertex; @@ -36,12 +36,11 @@ namespace o2::ft0 mTvxPerBcInfos.clear(); } - - EventsPerBcCalibrator::EventsPerBcCalibrator(uint32_t minNumberOfEntries, int32_t minAmplitudeSideA, int32_t minAmplitudeSideC): mMinNumberOfEntries(minNumberOfEntries), mMinAmplitudeSideA(minAmplitudeSideA), mMinAmplitudeSideC(minAmplitudeSideC) + EventsPerBcCalibrator::EventsPerBcCalibrator(uint32_t minNumberOfEntries, int32_t minAmplitudeSideA, int32_t minAmplitudeSideC) : mMinNumberOfEntries(minNumberOfEntries), mMinAmplitudeSideA(minAmplitudeSideA), mMinAmplitudeSideC(minAmplitudeSideC) { - LOG(info) << "Defined threshold for number of entires per slot: " << mMinNumberOfEntries; - LOG(info) << "Defined threshold for side A amplitude for event: " << mMinAmplitudeSideA; - LOG(info) << "Defined threshold for side C amplitude for event: " << mMinAmplitudeSideC; + LOG(info) << "Defined threshold for number of entires per slot: " << mMinNumberOfEntries; + LOG(info) << "Defined threshold for side A amplitude for event: " << mMinAmplitudeSideA; + LOG(info) << "Defined threshold for side C amplitude for event: " << mMinAmplitudeSideC; } bool EventsPerBcCalibrator::hasEnoughData(const EventsPerBcCalibrator::Slot& slot) const @@ -51,17 +50,17 @@ namespace o2::ft0 void EventsPerBcCalibrator::finalizeSlot(EventsPerBcCalibrator::Slot& slot) { - LOG(info) << "Finalizing slot from " << slot.getStartTimeMS() << " to " << slot.getEndTimeMS(); + LOG(info) << "Finalizing slot from " << slot.getStartTimeMS() << " to " << slot.getEndTimeMS(); o2::ft0::EventsPerBc* data = slot.getContainer(); mTvxPerBcs.emplace_back(std::make_unique("TvxPerBc", "FT0 TVX per BC", o2::constants::lhc::LHCMaxBunches, 0, o2::constants::lhc::LHCMaxBunches - 1)); - for(int bin = 0; bin < o2::constants::lhc::LHCMaxBunches; bin++) { + for (int bin = 0; bin < o2::constants::lhc::LHCMaxBunches; bin++) { mTvxPerBcs.back()->Fill(bin, data->mTvx[bin]); } auto clName = o2::utils::MemFileHelper::getClassName(*mTvxPerBcs.back()); auto flName = o2::ccdb::CcdbApi::generateFileName(clName); std::map metaData; mTvxPerBcInfos.emplace_back(std::make_unique("FT0/Calib/TvxPerBc", clName, flName, metaData, slot.getStartTimeMS(), slot.getEndTimeMS())); - LOG(info) << "Created new calibration object. Current number of objects: " << mTvxPerBcs.size(); + LOG(info) << "Created object valid from " << mTvxPerBcInfos.back()->getStartValidityTimestamp() << " to " << TvxPerBcInfos.back()->getEndValidityTimestamp() << "" } EventsPerBcCalibrator::Slot& EventsPerBcCalibrator::emplaceNewSlot(bool front, TFType tstart, TFType tend) diff --git a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx index 817fe5b3966de..206d20d212c96 100644 --- a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx +++ b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx @@ -10,19 +10,17 @@ o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext co outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "EventsPerBc"}, Lifetime::Sporadic); outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "EventsPerBc"}, Lifetime::Sporadic); DataProcessorSpec dataProcessorSpec{ - "FT0EventsPerBcProcessor", - inputs, - outputs, - AlgorithmSpec(adaptFromTask()), - Options{ - {"slot-len-sec", VariantType::UInt32, 3600u, {"Duration of each slot in seconds"}}, - {"slot-len-tf", VariantType::UInt32, 0u, {"Slot length in Time Frames (TFs)"}}, - {"one-object-per-run", VariantType::Bool, false, {"If set, workflow creates only one calibration object per run"}}, - {"min-entries-number", VariantType::UInt32, 0u, {"Minimum number of entries required for a slot to be valid"}}, - {"min-ampl-side-a", VariantType::Int, std::numeric_limits::min(), {"Amplitude threshold for Side A events"}}, - {"min-ampl-side-c", VariantType::Int, std::numeric_limits::min(), {"Amplitude threshold for Side C events"}} - } - }; + "FT0EventsPerBcProcessor", + inputs, + outputs, + AlgorithmSpec(adaptFromTask()), + Options{ + {"slot-len-sec", VariantType::UInt32, 3600u, {"Duration of each slot in seconds"}}, + {"slot-len-tf", VariantType::UInt32, 0u, {"Slot length in Time Frames (TFs)"}}, + {"one-object-per-run", VariantType::Bool, false, {"If set, workflow creates only one calibration object per run"}}, + {"min-entries-number", VariantType::UInt32, 0u, {"Minimum number of entries required for a slot to be valid"}}, + {"min-ampl-side-a", VariantType::Int, std::numeric_limits::min(), {"Amplitude threshold for Side A events"}}, + {"min-ampl-side-c", VariantType::Int, std::numeric_limits::min(), {"Amplitude threshold for Side C events"}}}}; WorkflowSpec workflow; workflow.emplace_back(dataProcessorSpec); diff --git a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h index c3a2b9101c46d..a91dc43943011 100644 --- a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h +++ b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h @@ -24,39 +24,39 @@ namespace o2::calibration void init(o2::framework::InitContext& ic) final { - if(ic.options().hasOption("slot-len-sec")) { - mSlotLenSec = ic.options().get("slot-len-sec"); - } - if(ic.options().hasOption("one-object-per-run")) { - mOneObjectPerRun = ic.options().get("one-object-per-run"); - } - if(ic.options().hasOption("slot-len-tf")) { - mSlotLen = ic.options().get("slot-len-tf"); - } - if(ic.options().hasOption("min-entries-number")) { - mMinNumberOfEntries = ic.options().get("min-entries-number"); - } - if(ic.options().hasOption("min-ampl-side-a")) { - mMinAmplitudeSideA = ic.options().get("min-ampl-side-a"); - } - if(ic.options().hasOption("min-ampl-side-c")) { - mMinAmplitudeSideC = ic.options().get("min-ampl-side-c"); - } + if (ic.options().hasOption("slot-len-sec")) { + mSlotLenSec = ic.options().get("slot-len-sec"); + } + if (ic.options().hasOption("one-object-per-run")) { + mOneObjectPerRun = ic.options().get("one-object-per-run"); + } + if (ic.options().hasOption("slot-len-tf")) { + mSlotLen = ic.options().get("slot-len-tf"); + } + if (ic.options().hasOption("min-entries-number")) { + mMinNumberOfEntries = ic.options().get("min-entries-number"); + } + if (ic.options().hasOption("min-ampl-side-a")) { + mMinAmplitudeSideA = ic.options().get("min-ampl-side-a"); + } + if (ic.options().hasOption("min-ampl-side-c")) { + mMinAmplitudeSideC = ic.options().get("min-ampl-side-c"); + } - mCalibrator = std::make_unique(mMinNumberOfEntries, mMinAmplitudeSideA, mMinAmplitudeSideC); + mCalibrator = std::make_unique(mMinNumberOfEntries, mMinAmplitudeSideA, mMinAmplitudeSideC); - if(mOneObjectPerRun) { - LOG(info) << "Only one object will be created at the end of run"; - mCalibrator->setUpdateAtTheEndOfRunOnly(); - } - if (mOneObjectPerRun == false && mSlotLen == 0){ - LOG(info) << "Defined slot interval to " << mSlotLenSec << " seconds"; - mCalibrator->setSlotLengthInSeconds(mSlotLenSec); - } - if (mOneObjectPerRun == false && mSlotLen != 0) { - LOG(info) << "Defined slot interval to " << mSlotLen << " TFS"; - mCalibrator->setSlotLength(mSlotLen); - } + if (mOneObjectPerRun) { + LOG(info) << "Only one object will be created at the end of run"; + mCalibrator->setUpdateAtTheEndOfRunOnly(); + } + if (mOneObjectPerRun == false && mSlotLen == 0) { + LOG(info) << "Defined slot interval to " << mSlotLenSec << " seconds"; + mCalibrator->setSlotLengthInSeconds(mSlotLenSec); + } + if (mOneObjectPerRun == false && mSlotLen != 0) { + LOG(info) << "Defined slot interval to " << mSlotLen << " TFS"; + mCalibrator->setSlotLength(mSlotLen); + } } void run(o2::framework::ProcessingContext& pc) final @@ -74,10 +74,10 @@ namespace o2::calibration void endOfStream(o2::framework::EndOfStreamContext& ec) final { - LOG(info) << "Received end-of-stream, checking for slot to finalize..."; - mCalibrator->checkSlotsToFinalize(); - sendOutput(ec.outputs()); - mCalibrator->initOutput(); + LOG(info) << "Received end-of-stream, checking for slot to finalize..."; + mCalibrator->checkSlotsToFinalize(); + sendOutput(ec.outputs()); + mCalibrator->initOutput(); } void sendOutput(o2::framework::DataAllocator& output) @@ -85,15 +85,15 @@ namespace o2::calibration using o2::framework::Output; const auto& tvxHists = mCalibrator->getTvxPerBc(); auto& infos = mCalibrator->getTvxPerBcCcdbInfo(); - for(unsigned int idx = 0; idx < tvxHists.size(); idx++){ - auto& info = infos[idx]; - const auto& payload = tvxHists[idx]; + for (unsigned int idx = 0; idx < tvxHists.size(); idx++) { + auto& info = infos[idx]; + const auto& payload = tvxHists[idx]; - auto image = o2::ccdb::CcdbApi::createObjectImage(payload.get(), info.get()); - LOG(info) << "Sending object " << info->getPath() << "/" << info->getFileName() << " of size " << image->size() - << " bytes, valid for " << info->getStartValidityTimestamp() << " : " << info->getEndValidityTimestamp(); - output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "EventsPerBc", idx}, *image.get()); - output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "EventsPerBc", idx}, *info.get()); + auto image = o2::ccdb::CcdbApi::createObjectImage(payload.get(), info.get()); + LOG(info) << "Sending object " << info->getPath() << "/" << info->getFileName() << " of size " << image->size() + << " bytes, valid for " << info->getStartValidityTimestamp() << " : " << info->getEndValidityTimestamp(); + output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "EventsPerBc", idx}, *image.get()); + output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "EventsPerBc", idx}, *info.get()); } if(tvxHists.size()) { From 05cc06eb78a2f7b9be9b977a49369e8b3c1918f5 Mon Sep 17 00:00:00 2001 From: wpierozak Date: Thu, 15 Jan 2026 10:12:32 +0100 Subject: [PATCH 09/14] FT0: Added readme to calibrations --- Detectors/FIT/FT0/calibration/README.md | 55 +++++++++++++++++++ .../calibration/src/EventsPerBcCalibrator.cxx | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 Detectors/FIT/FT0/calibration/README.md diff --git a/Detectors/FIT/FT0/calibration/README.md b/Detectors/FIT/FT0/calibration/README.md new file mode 100644 index 0000000000000..a21d09d9cc200 --- /dev/null +++ b/Detectors/FIT/FT0/calibration/README.md @@ -0,0 +1,55 @@ +# Calibrations + +## Events per BC Calibration +### Description +Generates histograms of **TVX per Bunch Crossing (BC)**. Events can be filtered by applying amplitude thresholds to the **A-side** and **C-side**. + +### Command-Line Options +| Option | Default | Description | +| :--- | :--- | :--- | +| `--slot-len-sec` | `3600` | Duration of each slot in seconds. | +| `--slot-len-tf` | `0` | Slot length in Time Frames (TFs). | +| `--one-object-per-run` | — | If set, the workflow creates only one calibration object per run. | +| `--min-entries-number` | `0` | Minimum number of entries required for a slot to be valid. | +| `--min-ampl-side-a` | `-2147483648` | Amplitude threshold for Side A events. | +| `--min-ampl-side-c` | `-2147483648` | Amplitude threshold for Side C events. | + +--- + +## How to Run + +### Simulation Data +To process simulation data, digits must first be converted to RAW format. The `o2-ft0-digi2raw` tool performs this conversion and generates the required configuration file. + +Once converted, you can run the calibration either as a single integrated workflow or by spawning as the sender and receiver components separately. + +#### Single Workflow Example +Execute the following command within the simulation directory: +``` +o2-raw-file-reader-workflow --input-conf FT0raw.cfg --loop -1 \ +| o2-ft0-flp-dpl-workflow --condition-backend=http://localhost:8080 \ +| o2-calibration-ft0-events-per-bc-processor --FT0EventsPerBcProcessor "--slot-len-sec=10" \ +| o2-calibration-ccdb-populator-workflow --ccdb-path=http://localhost:8080 +``` + +Sender example (in simulation directory): +``` +o2-raw-file-reader-workflow --input-conf FT0raw.cfg --loop -1 \ +| o2-ft0-flp-dpl-workflow --condition-backend=http://localhost:8080 \ +| o2-dpl-output-proxy --channel-config "name=downstream,method=connect,address=tcp://localhost:30453,type=push,transport=zeromq" --dataspec "downstream:FT0/DIGITSBC" +``` + +Receiver example: +``` +o2-dpl-raw-proxy --channel-config "name=readout-proxy,type=pull,method=bind,address=tcp://localhost:30453,rateLogging=1,transport=zeromq" --dataspec "A:FT0/DIGITSBC/0" \ +| o2-calibration-ft0-events-per-bc-processor --FT0EventsPerBcProcessor "--slot-len-sec=10 --min-ampl-side-a=0" \ +| o2-calibration-ccdb-populator-workflow --ccdb-path=http://localhost:8080/ +``` + +### CTF Data +Example: +``` +o2-ctf-reader-workflow --ctf-input ctf.root --onlyDet FT0 \ +| o2-calibration-ft0-events-per-bc-processor --FT0EventsPerBcProcessor "--slot-len-sec=10" \ +| o2-calibration-ccdb-populator-workflow --ccdb-path=http://localhost:8080/ +``` \ No newline at end of file diff --git a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx index 0e69a090b0c0e..d2507e2095087 100644 --- a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx +++ b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx @@ -60,7 +60,7 @@ namespace o2::ft0 auto flName = o2::ccdb::CcdbApi::generateFileName(clName); std::map metaData; mTvxPerBcInfos.emplace_back(std::make_unique("FT0/Calib/TvxPerBc", clName, flName, metaData, slot.getStartTimeMS(), slot.getEndTimeMS())); - LOG(info) << "Created object valid from " << mTvxPerBcInfos.back()->getStartValidityTimestamp() << " to " << TvxPerBcInfos.back()->getEndValidityTimestamp() << "" + LOG(info) << "Created object valid from " << mTvxPerBcInfos.back()->getStartValidityTimestamp() << " to " << mTvxPerBcInfos.back()->getEndValidityTimestamp(); } EventsPerBcCalibrator::Slot& EventsPerBcCalibrator::emplaceNewSlot(bool front, TFType tstart, TFType tend) From 864d008a0154c4128b5ad2d0c8ffda95fe84ab8c Mon Sep 17 00:00:00 2001 From: wpierozak Date: Thu, 15 Jan 2026 11:48:18 +0100 Subject: [PATCH 10/14] FT0: Changed calibration object name, implemented missing OrbitReset fetching --- Detectors/FIT/FT0/calibration/README.md | 2 +- .../FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx | 6 +++--- .../workflow/FT0EventsPerBcProcessor-Workflow.cxx | 9 ++++++++- .../FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h | 11 ++++++++++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Detectors/FIT/FT0/calibration/README.md b/Detectors/FIT/FT0/calibration/README.md index a21d09d9cc200..8905f91e33063 100644 --- a/Detectors/FIT/FT0/calibration/README.md +++ b/Detectors/FIT/FT0/calibration/README.md @@ -2,7 +2,7 @@ ## Events per BC Calibration ### Description -Generates histograms of **TVX per Bunch Crossing (BC)**. Events can be filtered by applying amplitude thresholds to the **A-side** and **C-side**. +Generates histograms of **Events per Bunch Crossing (BC)**. Events can be filtered by applying amplitude thresholds to the **A-side** and **C-side**. ### Command-Line Options | Option | Default | Description | diff --git a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx index d2507e2095087..a75113ecbb38b 100644 --- a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx +++ b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx @@ -52,14 +52,14 @@ namespace o2::ft0 { LOG(info) << "Finalizing slot from " << slot.getStartTimeMS() << " to " << slot.getEndTimeMS(); o2::ft0::EventsPerBc* data = slot.getContainer(); - mTvxPerBcs.emplace_back(std::make_unique("TvxPerBc", "FT0 TVX per BC", o2::constants::lhc::LHCMaxBunches, 0, o2::constants::lhc::LHCMaxBunches - 1)); + mTvxPerBcs.emplace_back(std::make_unique("EventsPerBc", "FT0 Events per BC", o2::constants::lhc::LHCMaxBunches, 0, o2::constants::lhc::LHCMaxBunches - 1)); for (int bin = 0; bin < o2::constants::lhc::LHCMaxBunches; bin++) { mTvxPerBcs.back()->Fill(bin, data->mTvx[bin]); } auto clName = o2::utils::MemFileHelper::getClassName(*mTvxPerBcs.back()); - auto flName = o2::ccdb::CcdbApi::generateFileName(clName); + auto flName = o2::ccdb::CcdbApi::generateFileName(clName) + ".root"; std::map metaData; - mTvxPerBcInfos.emplace_back(std::make_unique("FT0/Calib/TvxPerBc", clName, flName, metaData, slot.getStartTimeMS(), slot.getEndTimeMS())); + mTvxPerBcInfos.emplace_back(std::make_unique("FT0/Calib/EventsPerBc", clName, flName, metaData, slot.getStartTimeMS(), slot.getEndTimeMS())); LOG(info) << "Created object valid from " << mTvxPerBcInfos.back()->getStartValidityTimestamp() << " to " << mTvxPerBcInfos.back()->getEndValidityTimestamp(); } diff --git a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx index 206d20d212c96..9c9286d71ad38 100644 --- a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx +++ b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx @@ -5,6 +5,13 @@ o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext co using namespace o2::framework; using o2::calibration::FT0EventsPerBcProcessor; std::vector inputs; + auto ccdbRequest = std::make_shared(true, // orbitResetTime + false, // GRPECS=true + false, // GRPLHCIF + false, // GRPMagField + false, // askMatLUT + o2::base::GRPGeomRequest::None, // geometry + inputs); inputs.emplace_back("digits", "FT0", "DIGITSBC"); std::vector outputs; outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "EventsPerBc"}, Lifetime::Sporadic); @@ -13,7 +20,7 @@ o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext co "FT0EventsPerBcProcessor", inputs, outputs, - AlgorithmSpec(adaptFromTask()), + AlgorithmSpec(adaptFromTask(ccdbRequest)), Options{ {"slot-len-sec", VariantType::UInt32, 3600u, {"Duration of each slot in seconds"}}, {"slot-len-tf", VariantType::UInt32, 0u, {"Slot length in Time Frames (TFs)"}}, diff --git a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h index a91dc43943011..2e06b68fab4e8 100644 --- a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h +++ b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h @@ -10,6 +10,7 @@ #include "Framework/WorkflowSpec.h" #include "Framework/Task.h" #include "DetectorsCalibration/Utils.h" +#include "DetectorsBase/GRPGeomHelper.h" #include "DataFormatsFT0/Digit.h" #include "FT0Calibration/EventsPerBcCalibrator.h" @@ -20,10 +21,11 @@ namespace o2::calibration class FT0EventsPerBcProcessor final : public o2::framework::Task { public: - FT0EventsPerBcProcessor() = default; + FT0EventsPerBcProcessor(std::shared_ptr request): mCCDBRequest(request) {} void init(o2::framework::InitContext& ic) final { + o2::base::GRPGeomHelper::instance().setRequest(mCCDBRequest); if (ic.options().hasOption("slot-len-sec")) { mSlotLenSec = ic.options().get("slot-len-sec"); } @@ -59,8 +61,14 @@ namespace o2::calibration } } + void finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj) + { + o2::base::GRPGeomHelper::instance().finaliseCCDB(matcher, obj); + } + void run(o2::framework::ProcessingContext& pc) final { + o2::base::GRPGeomHelper::instance().checkUpdates(pc); auto digits = pc.inputs().get>("digits"); o2::base::TFIDInfoHelper::fillTFIDInfo(pc, mCalibrator->getCurrentTFInfo()); if(digits.size() == 0) { @@ -102,6 +110,7 @@ namespace o2::calibration } private: + std::shared_ptr mCCDBRequest; std::unique_ptr mCalibrator; bool mOneObjectPerRun; uint32_t mSlotLenSec; From 56e38b6d3d262c03fa5329b1a109112aa43add7a Mon Sep 17 00:00:00 2001 From: wpierozak Date: Thu, 15 Jan 2026 12:14:43 +0100 Subject: [PATCH 11/14] FT0 EventsPerBc calibration: storing histograms in float format, updated readme --- Detectors/FIT/FT0/calibration/README.md | 7 +++++++ .../include/FT0Calibration/EventsPerBcCalibrator.h | 2 +- .../FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Detectors/FIT/FT0/calibration/README.md b/Detectors/FIT/FT0/calibration/README.md index 8905f91e33063..ad050d5d4e486 100644 --- a/Detectors/FIT/FT0/calibration/README.md +++ b/Detectors/FIT/FT0/calibration/README.md @@ -19,6 +19,13 @@ Generates histograms of **Events per Bunch Crossing (BC)**. Events can be filter ## How to Run ### Simulation Data +First, it is important to digitize data with a non-zero run number, orbit, and timestamp. To set these parameters, one can use the `--configKeyValues` option, as shown in the example below. +``` +o2-sim-digitizer-workflow \ +--onlyDet FT0 \ +--configKeyValues="HBFUtils.nHBFPerTF=128;HBFUtils.orbitFirst=128;HBFUtils.orbitFirstSampled=256;HBFUtils.runNumber=560560;HBFUtils.timestamp=1768464099000" +``` + To process simulation data, digits must first be converted to RAW format. The `o2-ft0-digi2raw` tool performs this conversion and generates the required configuration file. Once converted, you can run the calibration either as a single integrated workflow or by spawning as the sender and receiver components separately. diff --git a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h index fdc2c85992b12..fbf6f6c08226d 100644 --- a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h +++ b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h @@ -30,7 +30,7 @@ namespace o2::ft0 const int32_t mMinAmplitudeSideA; const int32_t mMinAmplitudeSideC; - std::array mTvx{0.0}; + std::array mTvx{0.0}; size_t entries{0}; long startTimeStamp{0}; long stopTimeStamp{0}; diff --git a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx index a75113ecbb38b..0485698a390c4 100644 --- a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx +++ b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx @@ -12,14 +12,14 @@ namespace o2::ft0 { size_t oldEntries = entries; for(const auto& digit: data) { - double isVertex = digit.mTriggers.getVertex(); + float isVertex = digit.mTriggers.getVertex(); if (digit.mTriggers.getAmplA() < mMinAmplitudeSideA || digit.mTriggers.getAmplC() < mMinAmplitudeSideC) { continue; } mTvx[digit.mIntRecord.bc] += isVertex; entries += isVertex; } - LOG(debug) << "Container is filled with " << entries - oldEntries << " new VTX events"; + LOG(debug) << "Container is filled with " << entries - oldEntries << " new events"; } void EventsPerBc::merge(const EventsPerBc* prev) From 797d924126de4d266986728b8bd4c05704e9b5c3 Mon Sep 17 00:00:00 2001 From: wpierozak Date: Wed, 21 Jan 2026 15:49:37 +0100 Subject: [PATCH 12/14] Changed type of EventsPerBc calibration object to std::array --- .../FT0Calibration/EventsPerBcCalibrator.h | 33 ++++++++------- .../calibration/src/EventsPerBcCalibrator.cxx | 19 ++++----- .../FT0EventsPerBcProcessor-Workflow.cxx | 4 +- .../calibration/workflow/FT0EventsPerBcSpec.h | 2 +- Detectors/FIT/FT0/macros/CMakeLists.txt | 4 ++ Detectors/FIT/FT0/macros/FT0readEventsPerBc.C | 42 +++++++++++++++++++ 6 files changed, 75 insertions(+), 29 deletions(-) create mode 100644 Detectors/FIT/FT0/macros/FT0readEventsPerBc.C diff --git a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h index fbf6f6c08226d..be5cefe5d915b 100644 --- a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h +++ b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h @@ -30,7 +30,7 @@ namespace o2::ft0 const int32_t mMinAmplitudeSideA; const int32_t mMinAmplitudeSideC; - std::array mTvx{0.0}; + std::array mTvx{0.0}; size_t entries{0}; long startTimeStamp{0}; long stopTimeStamp{0}; @@ -42,27 +42,28 @@ namespace o2::ft0 { using Slot = o2::calibration::TimeSlot; using TFType = o2::calibration::TFType; + using EventsHistogram = std::array; - public: - EventsPerBcCalibrator(uint32_t minNumberOfEntries, int32_t minAmplitudeSideA, int32_t minAmplitudeSideC); + public: + EventsPerBcCalibrator(uint32_t minNumberOfEntries, int32_t minAmplitudeSideA, int32_t minAmplitudeSideC); - bool hasEnoughData(const Slot& slot) const override; - void initOutput() override; - void finalizeSlot(Slot& slot) override; - Slot& emplaceNewSlot(bool front, TFType tstart, TFType tend) override; + bool hasEnoughData(const Slot& slot) const override; + void initOutput() override; + void finalizeSlot(Slot& slot) override; + Slot& emplaceNewSlot(bool front, TFType tstart, TFType tend) override; - const std::vector>& getTvxPerBc() { return mTvxPerBcs; } - std::vector>& getTvxPerBcCcdbInfo() { return mTvxPerBcInfos; } + const std::vector& getTvxPerBc() { return mTvxPerBcs; } + std::vector>& getTvxPerBcCcdbInfo() { return mTvxPerBcInfos; } - private: - const uint32_t mMinNumberOfEntries; - const int32_t mMinAmplitudeSideA; - const int32_t mMinAmplitudeSideC; + private: + const uint32_t mMinNumberOfEntries; + const int32_t mMinAmplitudeSideA; + const int32_t mMinAmplitudeSideC; - std::vector> mTvxPerBcs; - std::vector> mTvxPerBcInfos; + std::vector mTvxPerBcs; + std::vector> mTvxPerBcInfos; - ClassDefOverride(EventsPerBcCalibrator, 1); + ClassDefOverride(EventsPerBcCalibrator, 1); }; } diff --git a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx index 0485698a390c4..99b0f0f8a9726 100644 --- a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx +++ b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx @@ -12,10 +12,10 @@ namespace o2::ft0 { size_t oldEntries = entries; for(const auto& digit: data) { - float isVertex = digit.mTriggers.getVertex(); - if (digit.mTriggers.getAmplA() < mMinAmplitudeSideA || digit.mTriggers.getAmplC() < mMinAmplitudeSideC) { - continue; - } + double isVertex = digit.mTriggers.getVertex(); + if (digit.mTriggers.getAmplA() < mMinAmplitudeSideA || digit.mTriggers.getAmplC() < mMinAmplitudeSideC) { + continue; + } mTvx[digit.mIntRecord.bc] += isVertex; entries += isVertex; } @@ -52,12 +52,11 @@ namespace o2::ft0 { LOG(info) << "Finalizing slot from " << slot.getStartTimeMS() << " to " << slot.getEndTimeMS(); o2::ft0::EventsPerBc* data = slot.getContainer(); - mTvxPerBcs.emplace_back(std::make_unique("EventsPerBc", "FT0 Events per BC", o2::constants::lhc::LHCMaxBunches, 0, o2::constants::lhc::LHCMaxBunches - 1)); - for (int bin = 0; bin < o2::constants::lhc::LHCMaxBunches; bin++) { - mTvxPerBcs.back()->Fill(bin, data->mTvx[bin]); - } - auto clName = o2::utils::MemFileHelper::getClassName(*mTvxPerBcs.back()); - auto flName = o2::ccdb::CcdbApi::generateFileName(clName) + ".root"; + mTvxPerBcs.emplace_back(std::move(data->mTvx)); + + auto clName = o2::utils::MemFileHelper::getClassName(mTvxPerBcs.back()); + auto flName = o2::ccdb::CcdbApi::generateFileName(clName); + std::map metaData; mTvxPerBcInfos.emplace_back(std::make_unique("FT0/Calib/EventsPerBc", clName, flName, metaData, slot.getStartTimeMS(), slot.getEndTimeMS())); LOG(info) << "Created object valid from " << mTvxPerBcInfos.back()->getStartValidityTimestamp() << " to " << mTvxPerBcInfos.back()->getEndValidityTimestamp(); diff --git a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx index 9c9286d71ad38..50b2b8d144da4 100644 --- a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx +++ b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx @@ -26,8 +26,8 @@ o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext co {"slot-len-tf", VariantType::UInt32, 0u, {"Slot length in Time Frames (TFs)"}}, {"one-object-per-run", VariantType::Bool, false, {"If set, workflow creates only one calibration object per run"}}, {"min-entries-number", VariantType::UInt32, 0u, {"Minimum number of entries required for a slot to be valid"}}, - {"min-ampl-side-a", VariantType::Int, std::numeric_limits::min(), {"Amplitude threshold for Side A events"}}, - {"min-ampl-side-c", VariantType::Int, std::numeric_limits::min(), {"Amplitude threshold for Side C events"}}}}; + {"min-ampl-side-a", VariantType::Int, 0, {"Amplitude threshold for Side A events"}}, + {"min-ampl-side-c", VariantType::Int, 0, {"Amplitude threshold for Side C events"}}}}; WorkflowSpec workflow; workflow.emplace_back(dataProcessorSpec); diff --git a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h index 2e06b68fab4e8..33826a76be3d2 100644 --- a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h +++ b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h @@ -97,7 +97,7 @@ namespace o2::calibration auto& info = infos[idx]; const auto& payload = tvxHists[idx]; - auto image = o2::ccdb::CcdbApi::createObjectImage(payload.get(), info.get()); + auto image = o2::ccdb::CcdbApi::createObjectImage(&payload, info.get()); LOG(info) << "Sending object " << info->getPath() << "/" << info->getFileName() << " of size " << image->size() << " bytes, valid for " << info->getStartValidityTimestamp() << " : " << info->getEndValidityTimestamp(); output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "EventsPerBc", idx}, *image.get()); diff --git a/Detectors/FIT/FT0/macros/CMakeLists.txt b/Detectors/FIT/FT0/macros/CMakeLists.txt index c4ed27d2513ba..d0d4dd4f28a73 100644 --- a/Detectors/FIT/FT0/macros/CMakeLists.txt +++ b/Detectors/FIT/FT0/macros/CMakeLists.txt @@ -12,3 +12,7 @@ o2_add_test_root_macro(FT0Misaligner.C PUBLIC_LINK_LIBRARIES O2::CCDB O2::FT0Simulation LABELS ft0) + +o2_add_test_root_macro(FT0readEventsPerBc.C + PUBLIC_LINK_LIBRARIES O2::CCDB + LABELS ft0) diff --git a/Detectors/FIT/FT0/macros/FT0readEventsPerBc.C b/Detectors/FIT/FT0/macros/FT0readEventsPerBc.C new file mode 100644 index 0000000000000..39effd6596c72 --- /dev/null +++ b/Detectors/FIT/FT0/macros/FT0readEventsPerBc.C @@ -0,0 +1,42 @@ + +#if !defined(__CLING__) || defined(__ROOTCLING__) + +#include +#include +#include "CCDB/CcdbApi.h" +#include "TH1F.h" +#endif + +#include "Framework/Logger.h" +#include "CommonConstants/LHCConstants.h" + +using EventsArray = std::array; +std::unique_ptr hist; +std::unique_ptr canvas; + +void FT0readEventsPerBc(std::string ccdbUrl, long timestamp) +{ + o2::ccdb::CcdbApi ccdbApi; + ccdbApi.init(ccdbUrl); + const std::string ccdbPath = "FT0/Calib/EventsPerBc"; + std::map metadata; + + if (timestamp < 0) { + timestamp = o2::ccdb::getCurrentTimestamp(); + } + + EventsArray* events = ccdbApi.retrieveFromTFileAny(ccdbPath, metadata, timestamp); + + if (!events) { + LOGP(fatal, "EventsPerBc object not found in {}/{} for timestamp {}.", ccdbUrl, ccdbPath, timestamp); + return; + } + + hist = std::make_unique("eventsPerBcHist", "Events per BC", o2::constants::lhc::LHCMaxBunches, 0, o2::constants::lhc::LHCMaxBunches - 1); + for (int idx = 0; idx < LhcOrbits; idx++) { + hist->Fill(idx, (*events)[idx]); + } + canvas = std::make_unique(); + hist->Draw(); + canvas->Draw(); +} \ No newline at end of file From 61f71e9aab0e9b4f471e2b4ad3637b73df90e2ec Mon Sep 17 00:00:00 2001 From: wpierozak Date: Wed, 21 Jan 2026 16:03:05 +0100 Subject: [PATCH 13/14] FT0: corrected macro FT0readEventsPerBc, corrected typo in calibration README --- Detectors/FIT/FT0/calibration/README.md | 2 +- Detectors/FIT/FT0/macros/FT0readEventsPerBc.C | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Detectors/FIT/FT0/calibration/README.md b/Detectors/FIT/FT0/calibration/README.md index ad050d5d4e486..2b14cf4fa594f 100644 --- a/Detectors/FIT/FT0/calibration/README.md +++ b/Detectors/FIT/FT0/calibration/README.md @@ -23,7 +23,7 @@ First, it is important to digitize data with a non-zero run number, orbit, and t ``` o2-sim-digitizer-workflow \ --onlyDet FT0 \ ---configKeyValues="HBFUtils.nHBFPerTF=128;HBFUtils.orbitFirst=128;HBFUtils.orbitFirstSampled=256;HBFUtils.runNumber=560560;HBFUtils.timestamp=1768464099000" +--configKeyValues="HBFUtils.nHBFPerTF=128;HBFUtils.orbitFirst=128;HBFUtils.orbitFirstSampled=256;HBFUtils.runNumber=560560;HBFUtils.startTime=1768464099000" ``` To process simulation data, digits must first be converted to RAW format. The `o2-ft0-digi2raw` tool performs this conversion and generates the required configuration file. diff --git a/Detectors/FIT/FT0/macros/FT0readEventsPerBc.C b/Detectors/FIT/FT0/macros/FT0readEventsPerBc.C index 39effd6596c72..db7dfc7b08359 100644 --- a/Detectors/FIT/FT0/macros/FT0readEventsPerBc.C +++ b/Detectors/FIT/FT0/macros/FT0readEventsPerBc.C @@ -33,7 +33,7 @@ void FT0readEventsPerBc(std::string ccdbUrl, long timestamp) } hist = std::make_unique("eventsPerBcHist", "Events per BC", o2::constants::lhc::LHCMaxBunches, 0, o2::constants::lhc::LHCMaxBunches - 1); - for (int idx = 0; idx < LhcOrbits; idx++) { + for (int idx = 0; idx < o2::constants::lhc::LHCMaxBunches; idx++) { hist->Fill(idx, (*events)[idx]); } canvas = std::make_unique(); From 3c5b1385cc9c2d566dcc43f718d197a1f7411bb6 Mon Sep 17 00:00:00 2001 From: ALICE Action Bot Date: Thu, 22 Jan 2026 13:54:34 +0000 Subject: [PATCH 14/14] Please consider the following formatting changes --- .../FT0Calibration/EventsPerBcCalibrator.h | 73 ++++--- .../calibration/src/EventsPerBcCalibrator.cxx | 114 +++++------ .../FT0EventsPerBcProcessor-Workflow.cxx | 48 ++--- .../calibration/workflow/FT0EventsPerBcSpec.h | 187 +++++++++--------- 4 files changed, 210 insertions(+), 212 deletions(-) diff --git a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h index be5cefe5d915b..2afdf33980428 100644 --- a/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h +++ b/Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h @@ -18,53 +18,52 @@ namespace o2::ft0 { - struct EventsPerBc - { - EventsPerBc(int32_t minAmplitudeSideA, int32_t minAmplitudeSideC) : mMinAmplitudeSideA(minAmplitudeSideA), mMinAmplitudeSideC(minAmplitudeSideC) {} +struct EventsPerBc { + EventsPerBc(int32_t minAmplitudeSideA, int32_t minAmplitudeSideC) : mMinAmplitudeSideA(minAmplitudeSideA), mMinAmplitudeSideC(minAmplitudeSideC) {} - size_t getEntries() const { return entries; } - void print() const; - void fill(const o2::dataformats::TFIDInfo& ti, const gsl::span data); - void merge(const EventsPerBc* prev); + size_t getEntries() const { return entries; } + void print() const; + void fill(const o2::dataformats::TFIDInfo& ti, const gsl::span data); + void merge(const EventsPerBc* prev); - const int32_t mMinAmplitudeSideA; - const int32_t mMinAmplitudeSideC; + const int32_t mMinAmplitudeSideA; + const int32_t mMinAmplitudeSideC; - std::array mTvx{0.0}; - size_t entries{0}; - long startTimeStamp{0}; - long stopTimeStamp{0}; + std::array mTvx{0.0}; + size_t entries{0}; + long startTimeStamp{0}; + long stopTimeStamp{0}; - ClassDefNV(EventsPerBc, 1); - }; + ClassDefNV(EventsPerBc, 1); +}; - class EventsPerBcCalibrator final : public o2::calibration::TimeSlotCalibration - { - using Slot = o2::calibration::TimeSlot; - using TFType = o2::calibration::TFType; - using EventsHistogram = std::array; +class EventsPerBcCalibrator final : public o2::calibration::TimeSlotCalibration +{ + using Slot = o2::calibration::TimeSlot; + using TFType = o2::calibration::TFType; + using EventsHistogram = std::array; - public: - EventsPerBcCalibrator(uint32_t minNumberOfEntries, int32_t minAmplitudeSideA, int32_t minAmplitudeSideC); + public: + EventsPerBcCalibrator(uint32_t minNumberOfEntries, int32_t minAmplitudeSideA, int32_t minAmplitudeSideC); - bool hasEnoughData(const Slot& slot) const override; - void initOutput() override; - void finalizeSlot(Slot& slot) override; - Slot& emplaceNewSlot(bool front, TFType tstart, TFType tend) override; + bool hasEnoughData(const Slot& slot) const override; + void initOutput() override; + void finalizeSlot(Slot& slot) override; + Slot& emplaceNewSlot(bool front, TFType tstart, TFType tend) override; - const std::vector& getTvxPerBc() { return mTvxPerBcs; } - std::vector>& getTvxPerBcCcdbInfo() { return mTvxPerBcInfos; } + const std::vector& getTvxPerBc() { return mTvxPerBcs; } + std::vector>& getTvxPerBcCcdbInfo() { return mTvxPerBcInfos; } - private: - const uint32_t mMinNumberOfEntries; - const int32_t mMinAmplitudeSideA; - const int32_t mMinAmplitudeSideC; + private: + const uint32_t mMinNumberOfEntries; + const int32_t mMinAmplitudeSideA; + const int32_t mMinAmplitudeSideC; - std::vector mTvxPerBcs; - std::vector> mTvxPerBcInfos; + std::vector mTvxPerBcs; + std::vector> mTvxPerBcInfos; - ClassDefOverride(EventsPerBcCalibrator, 1); - }; -} + ClassDefOverride(EventsPerBcCalibrator, 1); +}; +} // namespace o2::ft0 #endif diff --git a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx index 99b0f0f8a9726..e8e6eff79283f 100644 --- a/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx +++ b/Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx @@ -3,70 +3,70 @@ namespace o2::ft0 { - void EventsPerBc::print() const - { - LOG(info) << entries << " entries"; - } +void EventsPerBc::print() const +{ + LOG(info) << entries << " entries"; +} - void EventsPerBc::fill(const o2::dataformats::TFIDInfo& ti, const gsl::span data) - { - size_t oldEntries = entries; - for(const auto& digit: data) { - double isVertex = digit.mTriggers.getVertex(); - if (digit.mTriggers.getAmplA() < mMinAmplitudeSideA || digit.mTriggers.getAmplC() < mMinAmplitudeSideC) { - continue; - } - mTvx[digit.mIntRecord.bc] += isVertex; - entries += isVertex; - } - LOG(debug) << "Container is filled with " << entries - oldEntries << " new events"; +void EventsPerBc::fill(const o2::dataformats::TFIDInfo& ti, const gsl::span data) +{ + size_t oldEntries = entries; + for (const auto& digit : data) { + double isVertex = digit.mTriggers.getVertex(); + if (digit.mTriggers.getAmplA() < mMinAmplitudeSideA || digit.mTriggers.getAmplC() < mMinAmplitudeSideC) { + continue; } + mTvx[digit.mIntRecord.bc] += isVertex; + entries += isVertex; + } + LOG(debug) << "Container is filled with " << entries - oldEntries << " new events"; +} - void EventsPerBc::merge(const EventsPerBc* prev) - { - for(int bc = 0; bc < o2::constants::lhc::LHCMaxBunches; bc++){ - mTvx[bc] += prev->mTvx[bc]; - } - entries += prev->entries; - } +void EventsPerBc::merge(const EventsPerBc* prev) +{ + for (int bc = 0; bc < o2::constants::lhc::LHCMaxBunches; bc++) { + mTvx[bc] += prev->mTvx[bc]; + } + entries += prev->entries; +} - void EventsPerBcCalibrator::initOutput() - { - mTvxPerBcs.clear(); - mTvxPerBcInfos.clear(); - } +void EventsPerBcCalibrator::initOutput() +{ + mTvxPerBcs.clear(); + mTvxPerBcInfos.clear(); +} - EventsPerBcCalibrator::EventsPerBcCalibrator(uint32_t minNumberOfEntries, int32_t minAmplitudeSideA, int32_t minAmplitudeSideC) : mMinNumberOfEntries(minNumberOfEntries), mMinAmplitudeSideA(minAmplitudeSideA), mMinAmplitudeSideC(minAmplitudeSideC) - { - LOG(info) << "Defined threshold for number of entires per slot: " << mMinNumberOfEntries; - LOG(info) << "Defined threshold for side A amplitude for event: " << mMinAmplitudeSideA; - LOG(info) << "Defined threshold for side C amplitude for event: " << mMinAmplitudeSideC; - } +EventsPerBcCalibrator::EventsPerBcCalibrator(uint32_t minNumberOfEntries, int32_t minAmplitudeSideA, int32_t minAmplitudeSideC) : mMinNumberOfEntries(minNumberOfEntries), mMinAmplitudeSideA(minAmplitudeSideA), mMinAmplitudeSideC(minAmplitudeSideC) +{ + LOG(info) << "Defined threshold for number of entires per slot: " << mMinNumberOfEntries; + LOG(info) << "Defined threshold for side A amplitude for event: " << mMinAmplitudeSideA; + LOG(info) << "Defined threshold for side C amplitude for event: " << mMinAmplitudeSideC; +} - bool EventsPerBcCalibrator::hasEnoughData(const EventsPerBcCalibrator::Slot& slot) const - { - return slot.getContainer()->entries > mMinNumberOfEntries; - } +bool EventsPerBcCalibrator::hasEnoughData(const EventsPerBcCalibrator::Slot& slot) const +{ + return slot.getContainer()->entries > mMinNumberOfEntries; +} - void EventsPerBcCalibrator::finalizeSlot(EventsPerBcCalibrator::Slot& slot) - { - LOG(info) << "Finalizing slot from " << slot.getStartTimeMS() << " to " << slot.getEndTimeMS(); - o2::ft0::EventsPerBc* data = slot.getContainer(); - mTvxPerBcs.emplace_back(std::move(data->mTvx)); +void EventsPerBcCalibrator::finalizeSlot(EventsPerBcCalibrator::Slot& slot) +{ + LOG(info) << "Finalizing slot from " << slot.getStartTimeMS() << " to " << slot.getEndTimeMS(); + o2::ft0::EventsPerBc* data = slot.getContainer(); + mTvxPerBcs.emplace_back(std::move(data->mTvx)); - auto clName = o2::utils::MemFileHelper::getClassName(mTvxPerBcs.back()); - auto flName = o2::ccdb::CcdbApi::generateFileName(clName); + auto clName = o2::utils::MemFileHelper::getClassName(mTvxPerBcs.back()); + auto flName = o2::ccdb::CcdbApi::generateFileName(clName); - std::map metaData; - mTvxPerBcInfos.emplace_back(std::make_unique("FT0/Calib/EventsPerBc", clName, flName, metaData, slot.getStartTimeMS(), slot.getEndTimeMS())); - LOG(info) << "Created object valid from " << mTvxPerBcInfos.back()->getStartValidityTimestamp() << " to " << mTvxPerBcInfos.back()->getEndValidityTimestamp(); - } + std::map metaData; + mTvxPerBcInfos.emplace_back(std::make_unique("FT0/Calib/EventsPerBc", clName, flName, metaData, slot.getStartTimeMS(), slot.getEndTimeMS())); + LOG(info) << "Created object valid from " << mTvxPerBcInfos.back()->getStartValidityTimestamp() << " to " << mTvxPerBcInfos.back()->getEndValidityTimestamp(); +} - EventsPerBcCalibrator::Slot& EventsPerBcCalibrator::emplaceNewSlot(bool front, TFType tstart, TFType tend) - { - auto& cont = getSlots(); - auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend); - slot.setContainer(std::make_unique(mMinAmplitudeSideA, mMinAmplitudeSideC)); - return slot; - } -} \ No newline at end of file +EventsPerBcCalibrator::Slot& EventsPerBcCalibrator::emplaceNewSlot(bool front, TFType tstart, TFType tend) +{ + auto& cont = getSlots(); + auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend); + slot.setContainer(std::make_unique(mMinAmplitudeSideA, mMinAmplitudeSideC)); + return slot; +} +} // namespace o2::ft0 \ No newline at end of file diff --git a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx index 50b2b8d144da4..d6c4459c29b79 100644 --- a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx +++ b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx @@ -2,34 +2,34 @@ #include o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext const& cfgc) { - using namespace o2::framework; - using o2::calibration::FT0EventsPerBcProcessor; - std::vector inputs; - auto ccdbRequest = std::make_shared(true, // orbitResetTime - false, // GRPECS=true + using namespace o2::framework; + using o2::calibration::FT0EventsPerBcProcessor; + std::vector inputs; + auto ccdbRequest = std::make_shared(true, // orbitResetTime + false, // GRPECS=true false, // GRPLHCIF false, // GRPMagField false, // askMatLUT o2::base::GRPGeomRequest::None, // geometry inputs); - inputs.emplace_back("digits", "FT0", "DIGITSBC"); - std::vector outputs; - outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "EventsPerBc"}, Lifetime::Sporadic); - outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "EventsPerBc"}, Lifetime::Sporadic); - DataProcessorSpec dataProcessorSpec{ - "FT0EventsPerBcProcessor", - inputs, - outputs, - AlgorithmSpec(adaptFromTask(ccdbRequest)), - Options{ - {"slot-len-sec", VariantType::UInt32, 3600u, {"Duration of each slot in seconds"}}, - {"slot-len-tf", VariantType::UInt32, 0u, {"Slot length in Time Frames (TFs)"}}, - {"one-object-per-run", VariantType::Bool, false, {"If set, workflow creates only one calibration object per run"}}, - {"min-entries-number", VariantType::UInt32, 0u, {"Minimum number of entries required for a slot to be valid"}}, - {"min-ampl-side-a", VariantType::Int, 0, {"Amplitude threshold for Side A events"}}, - {"min-ampl-side-c", VariantType::Int, 0, {"Amplitude threshold for Side C events"}}}}; + inputs.emplace_back("digits", "FT0", "DIGITSBC"); + std::vector outputs; + outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "EventsPerBc"}, Lifetime::Sporadic); + outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "EventsPerBc"}, Lifetime::Sporadic); + DataProcessorSpec dataProcessorSpec{ + "FT0EventsPerBcProcessor", + inputs, + outputs, + AlgorithmSpec(adaptFromTask(ccdbRequest)), + Options{ + {"slot-len-sec", VariantType::UInt32, 3600u, {"Duration of each slot in seconds"}}, + {"slot-len-tf", VariantType::UInt32, 0u, {"Slot length in Time Frames (TFs)"}}, + {"one-object-per-run", VariantType::Bool, false, {"If set, workflow creates only one calibration object per run"}}, + {"min-entries-number", VariantType::UInt32, 0u, {"Minimum number of entries required for a slot to be valid"}}, + {"min-ampl-side-a", VariantType::Int, 0, {"Amplitude threshold for Side A events"}}, + {"min-ampl-side-c", VariantType::Int, 0, {"Amplitude threshold for Side C events"}}}}; - WorkflowSpec workflow; - workflow.emplace_back(dataProcessorSpec); - return workflow; + WorkflowSpec workflow; + workflow.emplace_back(dataProcessorSpec); + return workflow; } \ No newline at end of file diff --git a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h index 33826a76be3d2..53bef2a3979ac 100644 --- a/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h +++ b/Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h @@ -15,109 +15,108 @@ #include "DataFormatsFT0/Digit.h" #include "FT0Calibration/EventsPerBcCalibrator.h" - namespace o2::calibration { - class FT0EventsPerBcProcessor final : public o2::framework::Task - { - public: - FT0EventsPerBcProcessor(std::shared_ptr request): mCCDBRequest(request) {} - - void init(o2::framework::InitContext& ic) final - { - o2::base::GRPGeomHelper::instance().setRequest(mCCDBRequest); - if (ic.options().hasOption("slot-len-sec")) { - mSlotLenSec = ic.options().get("slot-len-sec"); - } - if (ic.options().hasOption("one-object-per-run")) { - mOneObjectPerRun = ic.options().get("one-object-per-run"); - } - if (ic.options().hasOption("slot-len-tf")) { - mSlotLen = ic.options().get("slot-len-tf"); - } - if (ic.options().hasOption("min-entries-number")) { - mMinNumberOfEntries = ic.options().get("min-entries-number"); - } - if (ic.options().hasOption("min-ampl-side-a")) { - mMinAmplitudeSideA = ic.options().get("min-ampl-side-a"); - } - if (ic.options().hasOption("min-ampl-side-c")) { - mMinAmplitudeSideC = ic.options().get("min-ampl-side-c"); - } +class FT0EventsPerBcProcessor final : public o2::framework::Task +{ + public: + FT0EventsPerBcProcessor(std::shared_ptr request) : mCCDBRequest(request) {} + + void init(o2::framework::InitContext& ic) final + { + o2::base::GRPGeomHelper::instance().setRequest(mCCDBRequest); + if (ic.options().hasOption("slot-len-sec")) { + mSlotLenSec = ic.options().get("slot-len-sec"); + } + if (ic.options().hasOption("one-object-per-run")) { + mOneObjectPerRun = ic.options().get("one-object-per-run"); + } + if (ic.options().hasOption("slot-len-tf")) { + mSlotLen = ic.options().get("slot-len-tf"); + } + if (ic.options().hasOption("min-entries-number")) { + mMinNumberOfEntries = ic.options().get("min-entries-number"); + } + if (ic.options().hasOption("min-ampl-side-a")) { + mMinAmplitudeSideA = ic.options().get("min-ampl-side-a"); + } + if (ic.options().hasOption("min-ampl-side-c")) { + mMinAmplitudeSideC = ic.options().get("min-ampl-side-c"); + } - mCalibrator = std::make_unique(mMinNumberOfEntries, mMinAmplitudeSideA, mMinAmplitudeSideC); + mCalibrator = std::make_unique(mMinNumberOfEntries, mMinAmplitudeSideA, mMinAmplitudeSideC); - if (mOneObjectPerRun) { - LOG(info) << "Only one object will be created at the end of run"; - mCalibrator->setUpdateAtTheEndOfRunOnly(); - } - if (mOneObjectPerRun == false && mSlotLen == 0) { - LOG(info) << "Defined slot interval to " << mSlotLenSec << " seconds"; - mCalibrator->setSlotLengthInSeconds(mSlotLenSec); - } - if (mOneObjectPerRun == false && mSlotLen != 0) { - LOG(info) << "Defined slot interval to " << mSlotLen << " TFS"; - mCalibrator->setSlotLength(mSlotLen); - } - } + if (mOneObjectPerRun) { + LOG(info) << "Only one object will be created at the end of run"; + mCalibrator->setUpdateAtTheEndOfRunOnly(); + } + if (mOneObjectPerRun == false && mSlotLen == 0) { + LOG(info) << "Defined slot interval to " << mSlotLenSec << " seconds"; + mCalibrator->setSlotLengthInSeconds(mSlotLenSec); + } + if (mOneObjectPerRun == false && mSlotLen != 0) { + LOG(info) << "Defined slot interval to " << mSlotLen << " TFS"; + mCalibrator->setSlotLength(mSlotLen); + } + } - void finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj) - { - o2::base::GRPGeomHelper::instance().finaliseCCDB(matcher, obj); - } + void finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj) + { + o2::base::GRPGeomHelper::instance().finaliseCCDB(matcher, obj); + } - void run(o2::framework::ProcessingContext& pc) final - { - o2::base::GRPGeomHelper::instance().checkUpdates(pc); - auto digits = pc.inputs().get>("digits"); - o2::base::TFIDInfoHelper::fillTFIDInfo(pc, mCalibrator->getCurrentTFInfo()); - if(digits.size() == 0) { - return; - } - mCalibrator->process(digits); - if(mOneObjectPerRun == false) { - sendOutput(pc.outputs()); - } - } + void run(o2::framework::ProcessingContext& pc) final + { + o2::base::GRPGeomHelper::instance().checkUpdates(pc); + auto digits = pc.inputs().get>("digits"); + o2::base::TFIDInfoHelper::fillTFIDInfo(pc, mCalibrator->getCurrentTFInfo()); + if (digits.size() == 0) { + return; + } + mCalibrator->process(digits); + if (mOneObjectPerRun == false) { + sendOutput(pc.outputs()); + } + } - void endOfStream(o2::framework::EndOfStreamContext& ec) final - { - LOG(info) << "Received end-of-stream, checking for slot to finalize..."; - mCalibrator->checkSlotsToFinalize(); - sendOutput(ec.outputs()); - mCalibrator->initOutput(); - } + void endOfStream(o2::framework::EndOfStreamContext& ec) final + { + LOG(info) << "Received end-of-stream, checking for slot to finalize..."; + mCalibrator->checkSlotsToFinalize(); + sendOutput(ec.outputs()); + mCalibrator->initOutput(); + } - void sendOutput(o2::framework::DataAllocator& output) - { - using o2::framework::Output; - const auto& tvxHists = mCalibrator->getTvxPerBc(); - auto& infos = mCalibrator->getTvxPerBcCcdbInfo(); - for (unsigned int idx = 0; idx < tvxHists.size(); idx++) { - auto& info = infos[idx]; - const auto& payload = tvxHists[idx]; + void sendOutput(o2::framework::DataAllocator& output) + { + using o2::framework::Output; + const auto& tvxHists = mCalibrator->getTvxPerBc(); + auto& infos = mCalibrator->getTvxPerBcCcdbInfo(); + for (unsigned int idx = 0; idx < tvxHists.size(); idx++) { + auto& info = infos[idx]; + const auto& payload = tvxHists[idx]; - auto image = o2::ccdb::CcdbApi::createObjectImage(&payload, info.get()); - LOG(info) << "Sending object " << info->getPath() << "/" << info->getFileName() << " of size " << image->size() - << " bytes, valid for " << info->getStartValidityTimestamp() << " : " << info->getEndValidityTimestamp(); - output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "EventsPerBc", idx}, *image.get()); - output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "EventsPerBc", idx}, *info.get()); - } + auto image = o2::ccdb::CcdbApi::createObjectImage(&payload, info.get()); + LOG(info) << "Sending object " << info->getPath() << "/" << info->getFileName() << " of size " << image->size() + << " bytes, valid for " << info->getStartValidityTimestamp() << " : " << info->getEndValidityTimestamp(); + output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "EventsPerBc", idx}, *image.get()); + output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "EventsPerBc", idx}, *info.get()); + } - if(tvxHists.size()) { - mCalibrator->initOutput(); - } - } + if (tvxHists.size()) { + mCalibrator->initOutput(); + } + } - private: - std::shared_ptr mCCDBRequest; - std::unique_ptr mCalibrator; - bool mOneObjectPerRun; - uint32_t mSlotLenSec; - o2::calibration::TFType mSlotLen; - uint32_t mMinNumberOfEntries; - int32_t mMinAmplitudeSideA; - int32_t mMinAmplitudeSideC; - }; -} + private: + std::shared_ptr mCCDBRequest; + std::unique_ptr mCalibrator; + bool mOneObjectPerRun; + uint32_t mSlotLenSec; + o2::calibration::TFType mSlotLen; + uint32_t mMinNumberOfEntries; + int32_t mMinAmplitudeSideA; + int32_t mMinAmplitudeSideC; +}; +} // namespace o2::calibration #endif \ No newline at end of file