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 <gsl/span>
12
13#include <InfoLogger/InfoLogger.hxx>
14
20#include "Framework/Logger.h"
21
22using namespace o2::emcal::reco_workflow;
23
24template <class InputType>
26{
27 // Check if InfoLoggerContext is active and if so set the Detector field
28 if (ctx.services().active<AliceO2::InfoLogger::InfoLoggerContext>()) {
29 auto& ilctx = ctx.services().get<AliceO2::InfoLogger::InfoLoggerContext>();
30 ilctx.setField(AliceO2::InfoLogger::InfoLoggerContext::FieldName::Detector, "EMC");
31 }
32
33 LOG(debug) << "[EMCALClusterizer - init] Initialize clusterizer ...";
34
35 // FIXME: Placeholder configuration -> get config from CCDB object
36 double timeCut = 10000, timeMin = 0, timeMax = 10000, gradientCut = 0.03, thresholdSeedEnergy = 0.1, thresholdCellEnergy = 0.05;
37 bool doEnergyGradientCut = true;
38
39 // FIXME: Hardcoded for run II run
40 // Get default geometry object if not yet set
41 mGeometry = Geometry::GetInstanceFromRunNumber(223409);
42 if (!mGeometry) {
43 LOG(error) << "Failure accessing geometry";
44 }
45
46 // Initialize clusterizer and link geometry
47 mClusterizer.initialize(timeCut, timeMin, timeMax, gradientCut, doEnergyGradientCut, thresholdSeedEnergy, thresholdCellEnergy);
48 mClusterizer.setGeometry(mGeometry);
49
50 mOutputClusters = new std::vector<o2::emcal::Cluster>();
51 mOutputCellDigitIndices = new std::vector<o2::emcal::ClusterIndex>();
52 mOutputTriggerRecord = new std::vector<o2::emcal::TriggerRecord>();
53 mOutputTriggerRecordIndices = new std::vector<o2::emcal::TriggerRecord>();
54 mTimer.Stop();
55 mTimer.Reset();
56}
57
58template <class InputType>
60{
61 LOG(debug) << "[EMCALClusterizer - run] called";
62 mTimer.Start(false);
63 std::string inputname;
64 std::string TrigName;
65
66 if constexpr (std::is_same<InputType, o2::emcal::Digit>::value) {
67 inputname = "digits";
68 TrigName = "digitstrgr";
69 } else if constexpr (std::is_same<InputType, o2::emcal::Cell>::value) {
70 inputname = "cells";
71 TrigName = "cellstrgr";
72 }
73
74 auto Inputs = ctx.inputs().get<gsl::span<InputType>>(inputname.c_str());
75 LOG(debug) << "[EMCALClusterizer - run] Received " << Inputs.size() << " Cells/digits, running clusterizer ...";
76
77 auto InputTriggerRecord = ctx.inputs().get<gsl::span<TriggerRecord>>(TrigName.c_str());
78 LOG(debug) << "[EMCALClusterizer - run] Received " << InputTriggerRecord.size() << " Trigger Records, running clusterizer ...";
79
80 mOutputClusters->clear();
81 mOutputCellDigitIndices->clear();
82 mOutputTriggerRecord->clear();
83 mOutputTriggerRecordIndices->clear();
84
85 int currentStartClusters = mOutputClusters->size();
86 int currentStartIndices = mOutputCellDigitIndices->size();
87 for (auto iTrgRcrd : InputTriggerRecord) {
88 if (Inputs.size() && iTrgRcrd.getNumberOfObjects()) {
89 mClusterizer.findClusters(gsl::span<const InputType>(&Inputs[iTrgRcrd.getFirstEntry()], iTrgRcrd.getNumberOfObjects())); // Find clusters on cells/digits (pass by ref)
90 } else {
91 mClusterizer.clear();
92 }
93 // Get found clusters + cell/digit indices for output
94 // * A cluster contains a range that correspond to the vector of cell/digit indices
95 // * The cell/digit index vector contains the indices of the clusterized cells/digits wrt to the original cell/digit array
96
97 auto outputClustersTemp = mClusterizer.getFoundClusters();
98 auto outputCellDigitIndicesTemp = mClusterizer.getFoundClustersInputIndices();
99
100 std::copy(outputClustersTemp->begin(), outputClustersTemp->end(), std::back_inserter(*mOutputClusters));
101 std::copy(outputCellDigitIndicesTemp->begin(), outputCellDigitIndicesTemp->end(), std::back_inserter(*mOutputCellDigitIndices));
102
103 mOutputTriggerRecord->emplace_back(iTrgRcrd.getBCData(), currentStartClusters, outputClustersTemp->size());
104 mOutputTriggerRecordIndices->emplace_back(iTrgRcrd.getBCData(), currentStartIndices, outputCellDigitIndicesTemp->size());
105
106 currentStartClusters = mOutputClusters->size();
107 currentStartIndices = mOutputCellDigitIndices->size();
108 }
109 LOG(debug) << "[EMCALClusterizer - run] Writing " << mOutputClusters->size() << " clusters ...";
110 ctx.outputs().snapshot(o2::framework::Output{o2::header::gDataOriginEMC, "CLUSTERS", 0}, *mOutputClusters);
111 ctx.outputs().snapshot(o2::framework::Output{o2::header::gDataOriginEMC, "INDICES", 0}, *mOutputCellDigitIndices);
112
113 ctx.outputs().snapshot(o2::framework::Output{o2::header::gDataOriginEMC, "CLUSTERSTRGR", 0}, *mOutputTriggerRecord);
114 ctx.outputs().snapshot(o2::framework::Output{o2::header::gDataOriginEMC, "INDICESTRGR", 0}, *mOutputTriggerRecordIndices);
115 mTimer.Stop();
116}
117
118template <class InputType>
120{
121 LOG(info) << "EMCALClusterizer timing: CPU: " << mTimer.CpuTime() << " Real: " << mTimer.RealTime() << " in " << mTimer.Counter() - 1 << " TFs";
122}
123
125{
126 std::vector<o2::framework::InputSpec> inputs;
127 std::vector<o2::framework::OutputSpec> outputs;
128
129 if (useDigits) {
130 inputs.emplace_back("digits", o2::header::gDataOriginEMC, "DIGITS", 0, o2::framework::Lifetime::Timeframe);
131 inputs.emplace_back("digitstrgr", o2::header::gDataOriginEMC, "DIGITSTRGR", 0, o2::framework::Lifetime::Timeframe);
132 } else {
133 inputs.emplace_back("cells", o2::header::gDataOriginEMC, "CELLS", 0, o2::framework::Lifetime::Timeframe);
134 inputs.emplace_back("cellstrgr", o2::header::gDataOriginEMC, "CELLSTRGR", 0, o2::framework::Lifetime::Timeframe);
135 }
136
137 outputs.emplace_back(o2::header::gDataOriginEMC, "CLUSTERS", 0, o2::framework::Lifetime::Timeframe);
138 outputs.emplace_back(o2::header::gDataOriginEMC, "INDICES", 0, o2::framework::Lifetime::Timeframe);
139 outputs.emplace_back(o2::header::gDataOriginEMC, "CLUSTERSTRGR", 0, o2::framework::Lifetime::Timeframe);
140 outputs.emplace_back(o2::header::gDataOriginEMC, "INDICESTRGR", 0, o2::framework::Lifetime::Timeframe);
141
142 if (useDigits) {
143 return o2::framework::DataProcessorSpec{"EMCALClusterizerSpec",
144 inputs,
145 outputs,
146 o2::framework::adaptFromTask<o2::emcal::reco_workflow::ClusterizerSpec<o2::emcal::Digit>>()};
147 } else {
148 return o2::framework::DataProcessorSpec{"EMCALClusterizerSpec",
149 inputs,
150 outputs,
151 o2::framework::adaptFromTask<o2::emcal::reco_workflow::ClusterizerSpec<o2::emcal::Cell>>()};
152 }
153}
std::ostringstream debug
void endOfStream(framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void run(framework::ProcessingContext &ctx) final
Run conversion of digits to cells.
void init(framework::InitContext &ctx) final
Initializing the ClusterizerSpec.
void snapshot(const Output &spec, T const &object)
ServiceRegistryRef services()
Definition InitContext.h:34
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.
bool active() const
Check if service of type T is currently active.
framework::DataProcessorSpec getClusterizerSpec(bool useDigits)
Creating DataProcessorSpec for the EMCAL Clusterizer Spec.
constexpr o2::header::DataOrigin gDataOriginEMC
Definition DataHeader.h:565
std::vector< InputSpec > Inputs
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"