Project
Loading...
Searching...
No Matches
CellConverterSpec.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11#include <fairlogger/Logger.h>
12
24
25using namespace o2::phos::reco_workflow;
26
28{
29 LOG(info) << "[PHOSCellConverter - init] Initialize converter " << (mPropagateMC ? "with" : "without") << " MC truth container";
30 if (mDefBadMap) {
31 LOG(info) << "No reading BadMap from ccdb requested, set default";
32 // create test BadMap and Calib objects. ClusterizerSpec should be owner
33 mBadMap = std::make_unique<BadChannelsMap>(); // Create empty bad map
34 mHasCalib = true;
35 }
36}
37
39{
40 // LOG(debug) << "[PHOSCellConverter - run] called";
41 // auto dataref = ctx.inputs().get("digits");
42 // auto const* phosheader = o2::framework::DataRefUtils::getHeader<o2::phos::PHOSBlockHeader*>(dataref);
43 // if (!phosheader->mHasPayload) {
44 auto digitsTR = ctx.inputs().get<std::vector<o2::phos::TriggerRecord>>("digitTriggerRecords");
45 if (!digitsTR.size()) { // nothing to process
46 mOutputCells.clear();
47 ctx.outputs().snapshot(o2::framework::Output{"PHS", "CELLS", 0}, mOutputCells);
48 mOutputCellTrigRecs.clear();
49 ctx.outputs().snapshot(o2::framework::Output{"PHS", "CELLTRIGREC", 0}, mOutputCellTrigRecs);
50 if (mPropagateMC) {
51 mOutputTruthCont.clear();
52 ctx.outputs().snapshot(o2::framework::Output{"PHS", "CELLSMCTR", 0}, mOutputTruthCont);
53 }
54 return;
55 }
56
57 if (mInitSimParams) { // trigger reading sim/rec parameters from CCDB, singleton initiated in Fetcher
58 ctx.inputs().get<o2::phos::PHOSSimParams*>("recoparams");
59 mInitSimParams = false;
60 }
61
62 mOutputCells.clear();
63 mOutputCellTrigRecs.clear();
64
65 auto digits = ctx.inputs().get<std::vector<o2::phos::Digit>>("digits");
66 std::unique_ptr<const o2::dataformats::MCTruthContainer<o2::phos::MCLabel>> truthcont(nullptr);
67 if (mPropagateMC) {
68 truthcont = ctx.inputs().get<o2::dataformats::MCTruthContainer<o2::phos::MCLabel>*>("digitsmctr");
69 mOutputTruthCont.clear();
70 }
71 if (mPropagateMC) {
72 LOG(info) << "[PHOSCellConverter - run] Received " << digits.size() << " digits and " << digitsTR.size() << " TriggerRecords" << truthcont->getNElements() << " MC labels";
73 } else {
74 LOG(info) << "[PHOSCellConverter - run] Received " << digits.size() << " digits and " << digitsTR.size() << " TriggerRecords";
75 }
76
77 // get BadMap from CCDB, once
78 if (!mHasCalib) {
79 auto badMapPtr = ctx.inputs().get<o2::phos::BadChannelsMap*>("badmap");
80 mBadMap = std::make_unique<BadChannelsMap>(*(badMapPtr.get()));
81 mHasCalib = true;
82 }
83
84 mOutputCells.reserve(digits.size()); // most of digits will be copied
85 int icell = 0;
86 for (const auto& tr : digitsTR) {
87 int iFirstDigit = tr.getFirstEntry();
88 int iLastDigit = iFirstDigit + tr.getNumberOfObjects();
89 int indexStart = mOutputCells.size();
90 for (int i = iFirstDigit; i < iLastDigit; i++) {
91 const auto& dig = digits.at(i);
92
93 if (dig.isTRU()) {
94 ChannelType_t chantype;
95 if (dig.isHighGain()) {
96 chantype = ChannelType_t::TRU2x2;
97 } else {
98 chantype = ChannelType_t::TRU4x4;
99 }
100 mOutputCells.emplace_back(dig.getAbsId(), dig.getAmplitude(), dig.getTime(), chantype);
101 } else {
102 // apply filter
103 if (!mBadMap->isChannelGood(dig.getAbsId())) {
104 continue;
105 }
106
107 ChannelType_t chantype;
108 if (dig.isHighGain()) {
109 chantype = ChannelType_t::HIGH_GAIN;
110 } else {
111 chantype = ChannelType_t::LOW_GAIN;
112 }
113 mOutputCells.emplace_back(dig.getAbsId(), dig.getAmplitude(), dig.getTime(), chantype);
114 if (mPropagateMC) { // copy MC info,
115 int iLab = dig.getLabel();
116 if (iLab > -1) {
117 mOutputTruthCont.addElements(icell, truthcont->getLabels(iLab));
118 } else {
119 MCLabel label(0, 0, 0, true, 0);
120 label.setNoise();
121 mOutputTruthCont.addElement(icell, label);
122 }
123 icell++;
124 }
125 }
126 }
127 mOutputCellTrigRecs.emplace_back(tr.getBCData(), indexStart, mOutputCells.size() - indexStart);
128 }
129 LOG(info) << "[PHOSCellConverter - run] Writing " << mOutputCells.size() << " cells, " << mOutputCellTrigRecs.size() << " Trig Records " << mOutputTruthCont.getNElements() << " PHOS labels ";
130
131 ctx.outputs().snapshot(o2::framework::Output{"PHS", "CELLS", 0}, mOutputCells);
132 ctx.outputs().snapshot(o2::framework::Output{"PHS", "CELLTRIGREC", 0}, mOutputCellTrigRecs);
133 if (mPropagateMC) {
134 ctx.outputs().snapshot(o2::framework::Output{"PHS", "CELLSMCTR", 0}, mOutputTruthCont);
135 }
136}
137
139{
140 std::vector<o2::framework::InputSpec> inputs;
141 std::vector<o2::framework::OutputSpec> outputs;
142 inputs.emplace_back("digits", o2::header::gDataOriginPHS, "DIGITS", 0, o2::framework::Lifetime::Timeframe);
143 inputs.emplace_back("digitTriggerRecords", o2::header::gDataOriginPHS, "DIGITTRIGREC", 0, o2::framework::Lifetime::Timeframe);
144 if (!defBadMap) {
145 inputs.emplace_back("badmap", o2::header::gDataOriginPHS, "PHS_Calib_BadMap", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("PHS/Calib/BadMap"));
146 }
147 inputs.emplace_back("recoparams", o2::header::gDataOriginPHS, "PHS_RecoParams", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("PHS/Config/RecoParams"));
148
149 outputs.emplace_back("PHS", "CELLS", 0, o2::framework::Lifetime::Timeframe);
150 outputs.emplace_back("PHS", "CELLTRIGREC", 0, o2::framework::Lifetime::Timeframe);
151 if (propagateMC) {
152 inputs.emplace_back("digitsmctr", "PHS", "DIGITSMCTR", 0, o2::framework::Lifetime::Timeframe);
153 outputs.emplace_back("PHS", "CELLSMCTR", 0, o2::framework::Lifetime::Timeframe);
154 }
155 return o2::framework::DataProcessorSpec{"PHOSCellConverterSpec",
156 inputs,
157 outputs,
158 o2::framework::adaptFromTask<o2::phos::reco_workflow::CellConverterSpec>(propagateMC, defBadMap)};
159}
A const (ready only) version of MCTruthContainer.
int32_t i
Definition of a container to keep Monte Carlo truth external to simulation objects.
A container to hold and manage MC truth information/labels.
void snapshot(const Output &spec, T const &object)
decltype(auto) get(R binding, int part=0) const
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
CCDB container for bad (masked) channels in PHOS.
void init(framework::InitContext &ctx) final
Initializing the CellConverterSpec.
void run(framework::ProcessingContext &ctx) final
Run conversion of digits to cells.
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
constexpr o2::header::DataOrigin gDataOriginPHS
Definition DataHeader.h:574
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
framework::DataProcessorSpec getCellConverterSpec(bool propagateMC, bool defBadMap)
Creating DataProcessorSpec for the PHOS Cell Converter Spec.
ChannelType_t
Definition Cell.h:51
@ TRU4x4
TRU channel, 4x4 trigger.
Definition Cell.h:55
@ LOW_GAIN
Low gain channel.
Definition Cell.h:52
@ HIGH_GAIN
High gain channel.
Definition Cell.h:53
@ TRU2x2
TRU channel, 2x2 trigger.
Definition Cell.h:54
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Digit > digits