Skip to content

Commit 797d924

Browse files
author
wpierozak
committed
Changed type of EventsPerBc calibration object to std::array
1 parent 56e38b6 commit 797d924

File tree

6 files changed

+75
-29
lines changed

6 files changed

+75
-29
lines changed

Detectors/FIT/FT0/calibration/include/FT0Calibration/EventsPerBcCalibrator.h

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace o2::ft0
3030
const int32_t mMinAmplitudeSideA;
3131
const int32_t mMinAmplitudeSideC;
3232

33-
std::array<float, o2::constants::lhc::LHCMaxBunches> mTvx{0.0};
33+
std::array<double, o2::constants::lhc::LHCMaxBunches> mTvx{0.0};
3434
size_t entries{0};
3535
long startTimeStamp{0};
3636
long stopTimeStamp{0};
@@ -42,27 +42,28 @@ namespace o2::ft0
4242
{
4343
using Slot = o2::calibration::TimeSlot<o2::ft0::EventsPerBc>;
4444
using TFType = o2::calibration::TFType;
45+
using EventsHistogram = std::array<double, o2::constants::lhc::LHCMaxBunches>;
4546

46-
public:
47-
EventsPerBcCalibrator(uint32_t minNumberOfEntries, int32_t minAmplitudeSideA, int32_t minAmplitudeSideC);
47+
public:
48+
EventsPerBcCalibrator(uint32_t minNumberOfEntries, int32_t minAmplitudeSideA, int32_t minAmplitudeSideC);
4849

49-
bool hasEnoughData(const Slot& slot) const override;
50-
void initOutput() override;
51-
void finalizeSlot(Slot& slot) override;
52-
Slot& emplaceNewSlot(bool front, TFType tstart, TFType tend) override;
50+
bool hasEnoughData(const Slot& slot) const override;
51+
void initOutput() override;
52+
void finalizeSlot(Slot& slot) override;
53+
Slot& emplaceNewSlot(bool front, TFType tstart, TFType tend) override;
5354

54-
const std::vector<std::unique_ptr<TH1F>>& getTvxPerBc() { return mTvxPerBcs; }
55-
std::vector<std::unique_ptr<o2::ccdb::CcdbObjectInfo>>& getTvxPerBcCcdbInfo() { return mTvxPerBcInfos; }
55+
const std::vector<EventsHistogram>& getTvxPerBc() { return mTvxPerBcs; }
56+
std::vector<std::unique_ptr<o2::ccdb::CcdbObjectInfo>>& getTvxPerBcCcdbInfo() { return mTvxPerBcInfos; }
5657

57-
private:
58-
const uint32_t mMinNumberOfEntries;
59-
const int32_t mMinAmplitudeSideA;
60-
const int32_t mMinAmplitudeSideC;
58+
private:
59+
const uint32_t mMinNumberOfEntries;
60+
const int32_t mMinAmplitudeSideA;
61+
const int32_t mMinAmplitudeSideC;
6162

62-
std::vector<std::unique_ptr<TH1F>> mTvxPerBcs;
63-
std::vector<std::unique_ptr<o2::ccdb::CcdbObjectInfo>> mTvxPerBcInfos;
63+
std::vector<EventsHistogram> mTvxPerBcs;
64+
std::vector<std::unique_ptr<o2::ccdb::CcdbObjectInfo>> mTvxPerBcInfos;
6465

65-
ClassDefOverride(EventsPerBcCalibrator, 1);
66+
ClassDefOverride(EventsPerBcCalibrator, 1);
6667
};
6768
}
6869

Detectors/FIT/FT0/calibration/src/EventsPerBcCalibrator.cxx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ namespace o2::ft0
1212
{
1313
size_t oldEntries = entries;
1414
for(const auto& digit: data) {
15-
float isVertex = digit.mTriggers.getVertex();
16-
if (digit.mTriggers.getAmplA() < mMinAmplitudeSideA || digit.mTriggers.getAmplC() < mMinAmplitudeSideC) {
17-
continue;
18-
}
15+
double isVertex = digit.mTriggers.getVertex();
16+
if (digit.mTriggers.getAmplA() < mMinAmplitudeSideA || digit.mTriggers.getAmplC() < mMinAmplitudeSideC) {
17+
continue;
18+
}
1919
mTvx[digit.mIntRecord.bc] += isVertex;
2020
entries += isVertex;
2121
}
@@ -52,12 +52,11 @@ namespace o2::ft0
5252
{
5353
LOG(info) << "Finalizing slot from " << slot.getStartTimeMS() << " to " << slot.getEndTimeMS();
5454
o2::ft0::EventsPerBc* data = slot.getContainer();
55-
mTvxPerBcs.emplace_back(std::make_unique<TH1F>("EventsPerBc", "FT0 Events per BC", o2::constants::lhc::LHCMaxBunches, 0, o2::constants::lhc::LHCMaxBunches - 1));
56-
for (int bin = 0; bin < o2::constants::lhc::LHCMaxBunches; bin++) {
57-
mTvxPerBcs.back()->Fill(bin, data->mTvx[bin]);
58-
}
59-
auto clName = o2::utils::MemFileHelper::getClassName(*mTvxPerBcs.back());
60-
auto flName = o2::ccdb::CcdbApi::generateFileName(clName) + ".root";
55+
mTvxPerBcs.emplace_back(std::move(data->mTvx));
56+
57+
auto clName = o2::utils::MemFileHelper::getClassName(mTvxPerBcs.back());
58+
auto flName = o2::ccdb::CcdbApi::generateFileName(clName);
59+
6160
std::map<std::string, std::string> metaData;
6261
mTvxPerBcInfos.emplace_back(std::make_unique<o2::ccdb::CcdbObjectInfo>("FT0/Calib/EventsPerBc", clName, flName, metaData, slot.getStartTimeMS(), slot.getEndTimeMS()));
6362
LOG(info) << "Created object valid from " << mTvxPerBcInfos.back()->getStartValidityTimestamp() << " to " << mTvxPerBcInfos.back()->getEndValidityTimestamp();

Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcProcessor-Workflow.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext co
2626
{"slot-len-tf", VariantType::UInt32, 0u, {"Slot length in Time Frames (TFs)"}},
2727
{"one-object-per-run", VariantType::Bool, false, {"If set, workflow creates only one calibration object per run"}},
2828
{"min-entries-number", VariantType::UInt32, 0u, {"Minimum number of entries required for a slot to be valid"}},
29-
{"min-ampl-side-a", VariantType::Int, std::numeric_limits<int32_t>::min(), {"Amplitude threshold for Side A events"}},
30-
{"min-ampl-side-c", VariantType::Int, std::numeric_limits<int32_t>::min(), {"Amplitude threshold for Side C events"}}}};
29+
{"min-ampl-side-a", VariantType::Int, 0, {"Amplitude threshold for Side A events"}},
30+
{"min-ampl-side-c", VariantType::Int, 0, {"Amplitude threshold for Side C events"}}}};
3131

3232
WorkflowSpec workflow;
3333
workflow.emplace_back(dataProcessorSpec);

Detectors/FIT/FT0/calibration/workflow/FT0EventsPerBcSpec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ namespace o2::calibration
9797
auto& info = infos[idx];
9898
const auto& payload = tvxHists[idx];
9999

100-
auto image = o2::ccdb::CcdbApi::createObjectImage(payload.get(), info.get());
100+
auto image = o2::ccdb::CcdbApi::createObjectImage(&payload, info.get());
101101
LOG(info) << "Sending object " << info->getPath() << "/" << info->getFileName() << " of size " << image->size()
102102
<< " bytes, valid for " << info->getStartValidityTimestamp() << " : " << info->getEndValidityTimestamp();
103103
output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "EventsPerBc", idx}, *image.get());

Detectors/FIT/FT0/macros/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ o2_add_test_root_macro(FT0Misaligner.C
1212
PUBLIC_LINK_LIBRARIES O2::CCDB
1313
O2::FT0Simulation
1414
LABELS ft0)
15+
16+
o2_add_test_root_macro(FT0readEventsPerBc.C
17+
PUBLIC_LINK_LIBRARIES O2::CCDB
18+
LABELS ft0)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
#if !defined(__CLING__) || defined(__ROOTCLING__)
3+
4+
#include <iostream>
5+
#include <array>
6+
#include "CCDB/CcdbApi.h"
7+
#include "TH1F.h"
8+
#endif
9+
10+
#include "Framework/Logger.h"
11+
#include "CommonConstants/LHCConstants.h"
12+
13+
using EventsArray = std::array<double, o2::constants::lhc::LHCMaxBunches>;
14+
std::unique_ptr<TH1F> hist;
15+
std::unique_ptr<TCanvas> canvas;
16+
17+
void FT0readEventsPerBc(std::string ccdbUrl, long timestamp)
18+
{
19+
o2::ccdb::CcdbApi ccdbApi;
20+
ccdbApi.init(ccdbUrl);
21+
const std::string ccdbPath = "FT0/Calib/EventsPerBc";
22+
std::map<std::string, std::string> metadata;
23+
24+
if (timestamp < 0) {
25+
timestamp = o2::ccdb::getCurrentTimestamp();
26+
}
27+
28+
EventsArray* events = ccdbApi.retrieveFromTFileAny<EventsArray>(ccdbPath, metadata, timestamp);
29+
30+
if (!events) {
31+
LOGP(fatal, "EventsPerBc object not found in {}/{} for timestamp {}.", ccdbUrl, ccdbPath, timestamp);
32+
return;
33+
}
34+
35+
hist = std::make_unique<TH1F>("eventsPerBcHist", "Events per BC", o2::constants::lhc::LHCMaxBunches, 0, o2::constants::lhc::LHCMaxBunches - 1);
36+
for (int idx = 0; idx < LhcOrbits; idx++) {
37+
hist->Fill(idx, (*events)[idx]);
38+
}
39+
canvas = std::make_unique<TCanvas>();
40+
hist->Draw();
41+
canvas->Draw();
42+
}

0 commit comments

Comments
 (0)