Skip to content

Commit 13e19c5

Browse files
author
wpierozak
committed
FT0: created first sketch of implementation of generation of TVX per Event calibration object
1 parent 70b1040 commit 13e19c5

File tree

4 files changed

+184
-0
lines changed

4 files changed

+184
-0
lines changed

Detectors/FIT/FT0/calibration/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,10 @@ o2_add_library(FT0Calibration
3333
PUBLIC_LINK_LIBRARIES
3434
O2::FT0Calibration
3535
)
36+
o2_add_executable(ft0-events-per-bc-processor
37+
COMPONENT_NAME calibration
38+
SOURCES workflow/FT0EventsPerBcProcessor-Workflow.cxx
39+
PUBLIC_LINK_LIBRARIES
40+
O2::FT0Calibration
41+
)
42+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#ifndef O2_FT0TVXPERBCID
2+
#define O2_FT0TVXPERBCID
3+
4+
#include <bitset>
5+
#include <array>
6+
7+
#include "CommonDataFormat/FlatHisto2D.h"
8+
#include "CommonConstants/LHCConstants.h"
9+
#include "DataFormatsFT0/SpectraInfoObject.h"
10+
#include "DetectorsCalibration/TimeSlotCalibration.h"
11+
#include "DetectorsCalibration/TimeSlot.h"
12+
#include "DataFormatsFT0/BcEvents.h"
13+
14+
namespace o2::ft0
15+
{
16+
struct EventsPerBc
17+
{
18+
EventsPerBc() = default;
19+
20+
size_t getEntries() const { return entries; }
21+
void print() const;
22+
void fill(const gsl::span<const o2::ft0::Digit> data);
23+
void merge(const EventsPerBc* prev);
24+
25+
std::array<double, o2::constants::lhc::LHCMaxBunches> mTvx{0.0};
26+
size_t entries{0};
27+
long startTimeStamp{0};
28+
long stopTimeStamp{0};
29+
};
30+
31+
class EventsPerBcCalibrator final : public o2::calibration::TimeSlotCalibration<o2::ft0::EventsPerBc>
32+
{
33+
using Slot = o2::calibration::TimeSlot<o2::ft0::EventsPerBc>;
34+
using TFType = o2::calibration::TFType;
35+
36+
public:
37+
EventsPerBcCalibrator()
38+
{
39+
setUpdateAtTheEndOfRunOnly();
40+
}
41+
42+
bool hasEnoughData(const Slot& slot) const final { return true; }
43+
void initOutput() final;
44+
void finalizeSlot(Slot& slot) final;
45+
Slot& emplaceNewSlot(bool front, TFType tstart, TFType tend) final;
46+
47+
const TH1F* getTvxPerBc() { return mTvxPerBc.get(); }
48+
const CcdbObjectInfo* getTvxPerBcCcdbInfo() { return mTvxPerBcInfo.get(); }
49+
50+
private:
51+
std::unique_ptr<TH1F> mTvxPerBc;
52+
std::unique_ptr<CcdbObjectInfo> mTvxPerBcInfo;
53+
};
54+
}
55+
56+
#endif
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include "FT0Calibration/EventsPerBcCalibrator.h"
2+
3+
namespace o2::ft0
4+
{
5+
void EventsPerBc::print() const
6+
{
7+
8+
}
9+
10+
void EventsPerBc::fill(const gsl::span<const o2::ft0::Digit> data)
11+
{
12+
for(const auto& digit: digits) {
13+
double isVertex = digit.mTriggers.isVertex();
14+
mTvx[digits.mIntRecord.bc] += isVertex;
15+
entries += isVertex;
16+
}
17+
}
18+
19+
void EventsPerBc::merge(const EventsPerBc* prev)
20+
{
21+
for(int bc = 0; bc < o2::constants::lhc::LHCMaxBunches; bc++){
22+
mTvx[bc] += prev->mTvx[bc];
23+
}
24+
entries += prev->mEntries;
25+
}
26+
27+
void EventsPerBcCalibrator::initOutput() final
28+
{
29+
mTvxPerBc.reset();
30+
mTvxPerBcInfo.reset();
31+
}
32+
33+
void EventsPerBcCalibrator::finalizeSlot(EventsPerBcCalibrator::Slot& slot) final
34+
{
35+
o2::ft0::EventsPerBc* data = slot.getContainer();
36+
mTvxPerBc = std::make_unique<TH1F>("TvxPerBc", "FT0 TVX per BC", o2::constants::lhc::LHCMaxBunches, 0, o2::constants::lhc::LHCMaxBunches - 1);
37+
for(int bin = 0; bin < o2::constants::lhc::LHCMaxBunches; bin++) {
38+
tvxsHist->fill(bin, data->mTvx[bin]);
39+
}
40+
auto clName = o2::utils::MemFileHelper::getClassName(*tvxsHist);
41+
auto flName = o2::ccdb::CcdbApi::generateFileName(clName);
42+
std::map<std::string, std::string> metaData;
43+
mTvxPerBcInfo = std::make_unique<CcdbObjectInfo>("FT0/Calib/TvxPerBc", clName, flName, metaData, slot.getStarTimeMs(), slot.getEndTimeStampMS());
44+
}
45+
46+
EventsPerBcCalibrator::Slot& EventsPerBcCalibrator::emplaceNewSlot(bool front, TFType tstart, TFType tend) final
47+
{
48+
auto& cont = getSlots();
49+
auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend);
50+
slot.setContainer(std::make_unique<EventsPerBc>());
51+
return slot;
52+
}
53+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include "Framework/runDataProcessing.h"
2+
#include "CommonUtils/ConfigurableParam.h"
3+
#include "Framework/ConfigParamSpec.h"
4+
#include <Framework/ConfigContext.h>
5+
#include "Framework/DeviceSpec.h"
6+
#include "Framework/WorkflowSpec.h"
7+
#include "Framework/Task.h"
8+
9+
#include "DataFormatsFT0/Digit.h"
10+
#include "DataFormatsFT0/BcEvents.h"
11+
#include "FT0Calibration/EventsPerBcCalibrator.h"
12+
13+
namespace o2::ft0
14+
{
15+
class FT0EventsPerBcProcessor final : public o2::framework::Task
16+
{
17+
void init(o2::framework::InitContext& ic) final
18+
{
19+
mCalibrator = std::make_unique<EventsPerBcCalibrator>();
20+
}
21+
22+
void run(o2::framework::ProcessContext& pc) final
23+
{
24+
auto digits = pc.inputs().get<gsl::span<o2::ft0::Digit>>("digits");
25+
mCalibrator->process(digits);
26+
}
27+
28+
void endOfStream(o2::framework::EndOfStreamContext& ec) final
29+
{
30+
mCalibrator->chekSlotToFinalize();
31+
sendOutput(ec.outputs());
32+
mCalibrator->initOutput();
33+
}
34+
35+
void sendOutput(DataAllocator& output)
36+
{
37+
TH1F* tvxHist = mCalibrator->getTvxPerBc();
38+
CcdbObjectInfo* info = mCalibrator->getTvxPerBcCcdbInfo();
39+
auto image = o2::ccdb::CcdbApi::createObjectImage(tvxHist, info);
40+
LOG(info) << "Sending object to CCDB";
41+
output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "EVENTS_PER_BC_INFO", 0}, *image.get());
42+
output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "EVENTS_PER_BC_INFO", 0}, info);
43+
}
44+
45+
private:
46+
std::unique_ptr<EventsPerBcCalibrator> mCalibrator;
47+
};
48+
}
49+
50+
WorkflowSpec defineDataProcessing(ConfigContext& const & cfgc)
51+
{
52+
using namespace o2::framework;
53+
std::vector<InputSpec> inputs;
54+
inputs.emplace_back("digits", "FT0", "DIGITSBC");
55+
std::vector<OutputSpec> outputs;
56+
outputs.emplace_back("eventsPerBcInfo", "FT0", "EVENTS_PER_BC_INFO")
57+
DataProcessorSpec dataProcessorSpec{
58+
"FT0EventsPerBcProcessor",
59+
inputs,
60+
outputs,
61+
AlgorithmSpec(adaptFromTask<o2::ft0::FT0EventsPerBcProcessor>()),
62+
Options{}
63+
};
64+
65+
WorkflowSpec workflow;
66+
workflow.emplace_back(dataProcessorSpec);
67+
return workflow;
68+
}

0 commit comments

Comments
 (0)