Project
Loading...
Searching...
No Matches
ClusterizerSpec.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
23
25
26using namespace o2::phos::reco_workflow;
27
29{
30 LOG(debug) << "[PHOSClusterizer - init] Initialize clusterizer ...";
31
32 // get BadMap and calibration CCDB
33
34 mClusterizer.initialize();
35 if (mDefBadMap) {
36 LOG(info) << "No reading BadMap/Calibration from ccdb requested, set default";
37 // create test BadMap and Calib objects. ClusterizerSpec should be owner
38 mCalibParams = std::make_unique<CalibParams>(1); // Create test calibration coefficients
39 mBadMap = std::make_unique<BadChannelsMap>(); // Create empty bad map
40 mClusterizer.setBadMap(mBadMap.get());
41 mClusterizer.setCalibration(mCalibParams.get()); // test calibration map
42 mHasCalib = true;
43 }
44}
45
47{
48
49 // Do not use ccdb if localtest
50 if (!mHasCalib) { // Default map and calibration was not set, use CCDB
51 // update BadMap and calibration if necessary
52 std::decay_t<decltype(ctx.inputs().get<o2::phos::BadChannelsMap*>("badmap"))> badMapPtr{};
53 badMapPtr = ctx.inputs().get<o2::phos::BadChannelsMap*>("badmap");
54 mClusterizer.setBadMap(badMapPtr.get());
55
56 std::decay_t<decltype(ctx.inputs().get<o2::phos::CalibParams*>("calib"))> calibPtr{};
57 calibPtr = ctx.inputs().get<o2::phos::CalibParams*>("calib");
58 mClusterizer.setCalibration(calibPtr.get());
59
60 if (!mSkipL1phase && !mPropagateMC) {
61 auto vec = ctx.inputs().get<std::vector<int>*>("l1phase");
62 mClusterizer.setL1phase((*vec)[0]);
63 }
64
65 mHasCalib = true;
66 }
67 if (mInitSimParams) { // trigger reading sim/rec parameters from CCDB, singleton initiated in Fetcher
68 ctx.inputs().get<o2::phos::PHOSSimParams*>("recoparams");
69 mInitSimParams = false;
70 }
71
72 if (mUseDigits) {
73 LOG(debug) << "PHOSClusterizer - run on digits called";
74
75 // auto dataref = ctx.inputs().get("digits");
76 // auto const* phosheader = o2::framework::DataRefUtils::getHeader<o2::phos::PHOSBlockHeader*>(dataref);
77 // if (!phosheader->mHasPayload) {
78 auto digitsTR = ctx.inputs().get<std::vector<o2::phos::TriggerRecord>>("digitTriggerRecords");
79 if (!digitsTR.size()) { // nothing to process
80 mOutputClusters.clear();
81 ctx.outputs().snapshot(o2::framework::Output{"PHS", "CLUSTERS", 0}, mOutputClusters);
82 if (mFullCluOutput) {
83 mOutputCluElements.clear();
84 ctx.outputs().snapshot(o2::framework::Output{"PHS", "CLUELEMENTS", 0}, mOutputCluElements);
85 }
86 mOutputClusterTrigRecs.clear();
87 ctx.outputs().snapshot(o2::framework::Output{"PHS", "CLUSTERTRIGREC", 0}, mOutputClusterTrigRecs);
88 if (mPropagateMC) {
89 mOutputTruthCont.clear();
90 ctx.outputs().snapshot(o2::framework::Output{"PHS", "CLUSTERTRUEMC", 0}, mOutputTruthCont);
91 }
92 return;
93 }
94 auto digits = ctx.inputs().get<std::vector<o2::phos::Digit>>("digits");
95 LOG(debug) << "[PHOSClusterizer - run] Received " << digitsTR.size() << " TR, running clusterizer ...";
96 // const o2::dataformats::MCTruthContainer<MCLabel>* truthcont=nullptr;
97 if (mPropagateMC) {
98 std::unique_ptr<const o2::dataformats::MCTruthContainer<o2::phos::MCLabel>> truthcont(ctx.inputs().get<o2::dataformats::MCTruthContainer<o2::phos::MCLabel>*>("digitsmctr"));
99 mClusterizer.process(digits, digitsTR, truthcont.get(), mOutputClusters, mOutputCluElements, mOutputClusterTrigRecs, mOutputTruthCont); // Find clusters on digits (pass by ref)
100 } else {
101 mClusterizer.process(digits, digitsTR, nullptr, mOutputClusters, mOutputCluElements, mOutputClusterTrigRecs, mOutputTruthCont); // Find clusters on digits (pass by ref)
102 }
103 } else {
104 auto cells = ctx.inputs().get<std::vector<o2::phos::Cell>>("cells");
105 // auto cells = ctx.inputs().get<gsl::span<o2::phos::Cell>>("cells");
106 LOG(debug) << "[PHOSClusterizer - run] Received " << cells.size() << " cells, running clusterizer ...";
107 // auto cellsTR = ctx.inputs().get<gsl::span<o2::phos::TriggerRecord>>("cellTriggerRecords");
108 auto cellsTR = ctx.inputs().get<std::vector<o2::phos::TriggerRecord>>("cellTriggerRecords");
109 if (mPropagateMC) {
110 std::unique_ptr<const o2::dataformats::MCTruthContainer<o2::phos::MCLabel>> truthcont(ctx.inputs().get<o2::dataformats::MCTruthContainer<o2::phos::MCLabel>*>("cellsmctr"));
111 // truthmap = ctx.inputs().get<gsl::span<uint>>("cellssmcmap");
112 mClusterizer.processCells(cells, cellsTR, truthcont.get(), mOutputClusters, mOutputCluElements, mOutputClusterTrigRecs, mOutputTruthCont); // Find clusters on digits (pass by ref)
113 } else {
114 mClusterizer.processCells(cells, cellsTR, nullptr, mOutputClusters, mOutputCluElements, mOutputClusterTrigRecs, mOutputTruthCont); // Find clusters on digits (pass by ref)
115 }
116 }
117
118 if (mPropagateMC) {
119 LOG(debug) << "[PHOSClusterizer - run] Writing " << mOutputClusters.size() << " clusters, " << mOutputClusterTrigRecs.size() << "TR and " << mOutputTruthCont.getIndexedSize() << " Labels";
120 } else {
121 LOG(debug) << "[PHOSClusterizer - run] Writing " << mOutputClusters.size() << " clusters and " << mOutputClusterTrigRecs.size() << " TR";
122 }
123 ctx.outputs().snapshot(o2::framework::Output{"PHS", "CLUSTERS", 0}, mOutputClusters);
124 if (mFullCluOutput) {
125 ctx.outputs().snapshot(o2::framework::Output{"PHS", "CLUELEMENTS", 0}, mOutputCluElements);
126 }
127 ctx.outputs().snapshot(o2::framework::Output{"PHS", "CLUSTERTRIGREC", 0}, mOutputClusterTrigRecs);
128 if (mPropagateMC) {
129 ctx.outputs().snapshot(o2::framework::Output{"PHS", "CLUSTERTRUEMC", 0}, mOutputTruthCont);
130 }
131}
132
134{
135 std::vector<o2::framework::InputSpec> inputs;
136 std::vector<o2::framework::OutputSpec> outputs;
137 inputs.emplace_back("digits", o2::header::gDataOriginPHS, "DIGITS", 0, o2::framework::Lifetime::Timeframe);
138 inputs.emplace_back("digitTriggerRecords", o2::header::gDataOriginPHS, "DIGITTRIGREC", 0, o2::framework::Lifetime::Timeframe);
139 if (!defBadMap) {
140 inputs.emplace_back("badmap", o2::header::gDataOriginPHS, "PHS_BadMap", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("PHS/Calib/BadMap"));
141 inputs.emplace_back("calib", o2::header::gDataOriginPHS, "PHS_Calib", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("PHS/Calib/CalibParams"));
142 }
143 inputs.emplace_back("recoparams", o2::header::gDataOriginPHS, "PHS_RecoParams", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("PHS/Config/RecoParams"));
144 if (propagateMC) {
145 inputs.emplace_back("digitsmctr", "PHS", "DIGITSMCTR", 0, o2::framework::Lifetime::Timeframe);
146 }
147 outputs.emplace_back("PHS", "CLUSTERS", 0, o2::framework::Lifetime::Timeframe);
148 if (fullClu) {
149 outputs.emplace_back("PHS", "CLUELEMENTS", 0, o2::framework::Lifetime::Timeframe);
150 }
151 outputs.emplace_back("PHS", "CLUSTERTRIGREC", 0, o2::framework::Lifetime::Timeframe);
152 if (propagateMC) {
153 outputs.emplace_back("PHS", "CLUSTERTRUEMC", 0, o2::framework::Lifetime::Timeframe);
154 }
155
156 return o2::framework::DataProcessorSpec{"PHOSClusterizerSpec",
157 inputs,
158 outputs,
159 o2::framework::adaptFromTask<o2::phos::reco_workflow::ClusterizerSpec>(propagateMC, true, fullClu, defBadMap, true),
161}
162
163o2::framework::DataProcessorSpec o2::phos::reco_workflow::getCellClusterizerSpec(bool propagateMC, bool fullClu, bool defBadMap, bool skipL1phase)
164{
165 // Cluaterizer with cell input
166 std::vector<o2::framework::InputSpec> inputs;
167 std::vector<o2::framework::OutputSpec> outputs;
168 inputs.emplace_back("cells", o2::header::gDataOriginPHS, "CELLS", 0, o2::framework::Lifetime::Timeframe);
169 inputs.emplace_back("cellTriggerRecords", o2::header::gDataOriginPHS, "CELLTRIGREC", 0, o2::framework::Lifetime::Timeframe);
170 if (!defBadMap) {
171 inputs.emplace_back("badmap", o2::header::gDataOriginPHS, "PHS_BadMap", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("PHS/Calib/BadMap"));
172 inputs.emplace_back("calib", o2::header::gDataOriginPHS, "PHS_Calib", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("PHS/Calib/CalibParams"));
173 if (!skipL1phase && !propagateMC) {
174 inputs.emplace_back("l1phase", o2::header::gDataOriginPHS, "PHS_L1phase", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("PHS/Calib/L1phase"));
175 }
176 }
177 inputs.emplace_back("recoparams", o2::header::gDataOriginPHS, "PHS_RecoParams", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("PHS/Config/RecoParams"));
178 if (propagateMC) {
179 inputs.emplace_back("cellsmctr", "PHS", "CELLSMCTR", 0, o2::framework::Lifetime::Timeframe);
180 }
181 outputs.emplace_back("PHS", "CLUSTERS", 0, o2::framework::Lifetime::Timeframe);
182 if (fullClu) {
183 outputs.emplace_back("PHS", "CLUELEMENTS", 0, o2::framework::Lifetime::Timeframe);
184 }
185 outputs.emplace_back("PHS", "CLUSTERTRIGREC", 0, o2::framework::Lifetime::Timeframe);
186 if (propagateMC) {
187 outputs.emplace_back("PHS", "CLUSTERTRUEMC", 0, o2::framework::Lifetime::Timeframe);
188 }
189
190 return o2::framework::DataProcessorSpec{"PHOSClusterizerSpec",
191 inputs,
192 outputs,
193 o2::framework::adaptFromTask<o2::phos::reco_workflow::ClusterizerSpec>(propagateMC, false, fullClu, defBadMap, skipL1phase),
195}
Definition of the Names Generator class.
std::ostringstream debug
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 processCells(gsl::span< const Cell > digits, gsl::span< const TriggerRecord > dtr, const o2::dataformats::MCTruthContainer< MCLabel > *dmc, std::vector< Cluster > &clusters, std::vector< CluElement > &cluel, std::vector< TriggerRecord > &rigRec, o2::dataformats::MCTruthContainer< MCLabel > &cluMC)
void setBadMap(const o2::phos::BadChannelsMap *m)
Definition Clusterer.h:49
void setCalibration(const o2::phos::CalibParams *c)
Definition Clusterer.h:50
void process(gsl::span< const Digit > digits, gsl::span< const TriggerRecord > dtr, const o2::dataformats::MCTruthContainer< MCLabel > *dmc, std::vector< Cluster > &clusters, std::vector< CluElement > &cluel, std::vector< TriggerRecord > &rigRec, o2::dataformats::MCTruthContainer< MCLabel > &cluMC)
Definition Clusterer.cxx:50
void setL1phase(int phase)
Definition Clusterer.h:51
void run(framework::ProcessingContext &ctx) final
Clusterizes digits into clusters.
void init(framework::InitContext &ctx) final
Initializing the ClusterizerSpec.
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)
std::vector< ConfigParamSpec > Options
framework::DataProcessorSpec getClusterizerSpec(bool propagateMC, bool fillFullClu, bool defBadMap=false)
Creating DataProcessorSpec for the PHOS Clusterizer Spec.
framework::DataProcessorSpec getCellClusterizerSpec(bool propagateMC, bool fillFullClu, bool defBadMap=false, bool skipL1phase=true)
std::vector< o2::ctf::BufferType > vec
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Cell > cells
std::vector< Digit > digits