Skip to content
Open

O2 6563 #14986

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 48 additions & 23 deletions Detectors/FIT/FT0/calibration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,51 @@
# 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
)
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
ROOT::Hist
)

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

Check failure on line 37 in Detectors/FIT/FT0/calibration/CMakeLists.txt

View workflow job for this annotation

GitHub Actions / PR formatting / whitespace

Trailing spaces

Remove the trailing spaces at the end of the line.
workflow/FT0TimeOffsetCalibration-Workflow.cxx
PUBLIC_LINK_LIBRARIES
O2::FT0Calibration O2::FITCalibration
)

o2_add_executable(ft0-time-spectra-processor
COMPONENT_NAME calibration
SOURCES

Check failure on line 45 in Detectors/FIT/FT0/calibration/CMakeLists.txt

View workflow job for this annotation

GitHub Actions / PR formatting / whitespace

Trailing spaces

Remove the trailing spaces at the end of the line.
workflow/FT0TimeSpectraProcessor-Workflow.cxx
PUBLIC_LINK_LIBRARIES
O2::FT0Calibration
)

o2_add_executable(ft0-events-per-bc-processor
COMPONENT_NAME calibration
SOURCES

Check failure on line 53 in Detectors/FIT/FT0/calibration/CMakeLists.txt

View workflow job for this annotation

GitHub Actions / PR formatting / whitespace

Trailing spaces

Remove the trailing spaces at the end of the line.
workflow/FT0EventsPerBcProcessor-Workflow.cxx
PUBLIC_LINK_LIBRARIES
O2::FT0Calibration
O2::Framework
O2::CCDB
)

Check failure on line 60 in Detectors/FIT/FT0/calibration/CMakeLists.txt

View workflow job for this annotation

GitHub Actions / PR formatting / whitespace

Trailing spaces

Remove the trailing spaces at the end of the line.
62 changes: 62 additions & 0 deletions Detectors/FIT/FT0/calibration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Calibrations

## Events per BC Calibration
### Description
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 |
| :--- | :--- | :--- |
| `--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
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.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.

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/

Check failure on line 53 in Detectors/FIT/FT0/calibration/README.md

View workflow job for this annotation

GitHub Actions / PR formatting / whitespace

Trailing spaces

Remove the trailing spaces at the end of the line.
```

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

Check failure on line 61 in Detectors/FIT/FT0/calibration/README.md

View workflow job for this annotation

GitHub Actions / PR formatting / whitespace

Trailing spaces

Remove the trailing spaces at the end of the line.
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#ifndef O2_FT0TVXPERBCID
#define O2_FT0TVXPERBCID

#include <bitset>
#include <array>
#include <limits>
#include <TH1F.h>

#include "CommonDataFormat/FlatHisto2D.h"
#include "CommonConstants/LHCConstants.h"

Check failure on line 10 in Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h

View workflow job for this annotation

GitHub Actions / PR formatting / copyright headers

Missing or malformed copyright notice

This source file is missing the correct copyright notice.
#include "DataFormatsFT0/SpectraInfoObject.h"
#include "DataFormatsFT0/Digit.h"
#include "DetectorsCalibration/TimeSlotCalibration.h"
#include "DetectorsCalibration/TimeSlot.h"
#include "CommonDataFormat/TFIDInfo.h"
#include "TH1F.h"
#include "Rtypes.h"

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<const o2::ft0::Digit> data);
void merge(const EventsPerBc* prev);

const int32_t mMinAmplitudeSideA;
const int32_t mMinAmplitudeSideC;

std::array<double, o2::constants::lhc::LHCMaxBunches> mTvx{0.0};
size_t entries{0};
long startTimeStamp{0};
long stopTimeStamp{0};

ClassDefNV(EventsPerBc, 1);
};

class EventsPerBcCalibrator final : public o2::calibration::TimeSlotCalibration<o2::ft0::EventsPerBc>
{
using Slot = o2::calibration::TimeSlot<o2::ft0::EventsPerBc>;
using TFType = o2::calibration::TFType;
using EventsHistogram = std::array<double, o2::constants::lhc::LHCMaxBunches>;

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;

const std::vector<EventsHistogram>& getTvxPerBc() { return mTvxPerBcs; }
std::vector<std::unique_ptr<o2::ccdb::CcdbObjectInfo>>& getTvxPerBcCcdbInfo() { return mTvxPerBcInfos; }

private:
const uint32_t mMinNumberOfEntries;
const int32_t mMinAmplitudeSideA;
const int32_t mMinAmplitudeSideC;

std::vector<EventsHistogram> mTvxPerBcs;
std::vector<std::unique_ptr<o2::ccdb::CcdbObjectInfo>> mTvxPerBcInfos;

ClassDefOverride(EventsPerBcCalibrator, 1);
};
} // namespace o2::ft0

#endif
72 changes: 72 additions & 0 deletions Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "FT0Calibration/EventsPerBcCalibrator.h"
#include "CommonUtils/MemFileHelper.h"

namespace o2::ft0
{
void EventsPerBc::print() const
{
LOG(info) << entries << " entries";
}

Check failure on line 10 in Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx

View workflow job for this annotation

GitHub Actions / PR formatting / copyright headers

Missing or malformed copyright notice

This source file is missing the correct copyright notice.
void EventsPerBc::fill(const o2::dataformats::TFIDInfo& ti, const gsl::span<const o2::ft0::Digit> 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 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;
}

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

auto clName = o2::utils::MemFileHelper::getClassName(mTvxPerBcs.back());
auto flName = o2::ccdb::CcdbApi::generateFileName(clName);

std::map<std::string, std::string> metaData;
mTvxPerBcInfos.emplace_back(std::make_unique<o2::ccdb::CcdbObjectInfo>("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<EventsPerBc>(mMinAmplitudeSideA, mMinAmplitudeSideC));
return slot;
}
} // namespace o2::ft0
4 changes: 3 additions & 1 deletion Detectors/FIT/FT0/calibration/src/FT0CalibrationLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
#pragma link off all functions;

#pragma link C++ class o2::ft0::FT0TimeOffsetSlotContainer + ;
#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
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "FT0EventsPerBcSpec.h"
#include <limits>
o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext const& cfgc)
{
using namespace o2::framework;
using o2::calibration::FT0EventsPerBcProcessor;
std::vector<InputSpec> inputs;
auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(true, // orbitResetTime
false, // GRPECS=true
false, // GRPLHCIF

Check failure on line 10 in Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx

View workflow job for this annotation

GitHub Actions / PR formatting / copyright headers

Missing or malformed copyright notice

This source file is missing the correct copyright notice.
false, // GRPMagField
false, // askMatLUT
o2::base::GRPGeomRequest::None, // geometry
inputs);
inputs.emplace_back("digits", "FT0", "DIGITSBC");
std::vector<OutputSpec> 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<FT0EventsPerBcProcessor>(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;
}
Loading
Loading