Project
Loading...
Searching...
No Matches
AnalysisClusterSpec.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#include "EMCALBase/Geometry.h"
23#include <TGeoManager.h>
25
26using namespace o2::emcal::reco_workflow;
27
28template <class InputType>
30{
32 static bool initOnceDone = false;
33 if (!initOnceDone) { // this params need to be queried only once
34 initOnceDone = true;
35 // FIXME: Hardcoded for run II run
36 // Get default geometry object if not yet set
37 // gGeoManager->Import("/Users/hadi/Clusterizer/O2geometry.root");
38 mGeometry = Geometry::GetInstanceFromRunNumber(223409);
39 if (!mGeometry) {
40 LOG(error) << "Failure accessing geometry";
41 }
42 double timeCut = 10000, timeMin = 0, timeMax = 10000, gradientCut = 0.03, thresholdSeedEnergy = 0.1, thresholdCellEnergy = 0.05;
43 bool doEnergyGradientCut = true;
44
45 // Initialize clusterizer and link geometry
46 mClusterizer.initialize(timeCut, timeMin, timeMax, gradientCut, doEnergyGradientCut, thresholdSeedEnergy, thresholdCellEnergy);
47 mClusterizer.setGeometry(mGeometry);
48 }
49}
50
51template <class InputType>
53{
54 if (o2::base::GRPGeomHelper::instance().finaliseCCDB(matcher, obj)) {
55 return;
56 }
57}
58
59template <class InputType>
61{
63
64 if (ctx.services().active<AliceO2::InfoLogger::InfoLoggerContext>()) {
65 auto& ilctx = ctx.services().get<AliceO2::InfoLogger::InfoLoggerContext>();
66 ilctx.setField(AliceO2::InfoLogger::InfoLoggerContext::FieldName::Detector, "EMC");
67 }
68
69 LOG(debug) << "[EMCALClusterizer - init] Initialize clusterizer ...";
70
71 // FIXME: Placeholder configuration -> get config from CCDB object
72
73 mEventHandler = new o2::emcal::EventHandler<InputType>();
74
75 mClusterFactory = new o2::emcal::ClusterFactory<InputType>();
76
77 mOutputAnaClusters = new std::vector<o2::emcal::AnalysisCluster>();
78}
79
80template <class InputType>
82{
83 LOG(debug) << "[EMCALClusterizer - run] called";
84 updateTimeDependentParams(ctx);
85 std::string inputname;
86 std::string TrigName;
87
88 if constexpr (std::is_same<InputType, o2::emcal::Digit>::value) {
89 inputname = "digits";
90 TrigName = "digitstrgr";
91 } else if constexpr (std::is_same<InputType, o2::emcal::Cell>::value) {
92 inputname = "cells";
93 TrigName = "cellstrgr";
94 }
95
96 auto Inputs = ctx.inputs().get<gsl::span<InputType>>(inputname.c_str());
97 LOG(debug) << "[EMCALClusterizer - run] Received " << Inputs.size() << " Cells/digits, running clusterizer ...";
98
99 auto InputTriggerRecord = ctx.inputs().get<gsl::span<TriggerRecord>>(TrigName.c_str());
100 LOG(debug) << "[EMCALClusterizer - run] Received " << InputTriggerRecord.size() << " Trigger Records, running clusterizer ...";
101
102 mOutputAnaClusters->clear();
103
104 std::vector<o2::emcal::Cluster> outputClusters;
105 std::vector<int> outputCellDigitIndices;
106 std::vector<o2::emcal::TriggerRecord> outputTriggerRecord;
107 std::vector<o2::emcal::TriggerRecord> outputTriggerRecordIndices;
108
109 int currentStartClusters = 0;
110 int currentStartIndices = 0;
111
112 for (auto iTrgRcrd : InputTriggerRecord) {
113
114 mClusterizer.findClusters(gsl::span<const InputType>(&Inputs[iTrgRcrd.getFirstEntry()], iTrgRcrd.getNumberOfObjects())); // Find clusters on cells/digits (pass by ref)
115
116 // Get found clusters + cell/digit indices for output
117 // * A cluster contains a range that correspond to the vector of cell/digit indices
118 // * The cell/digit index vector contains the indices of the clusterized cells/digits wrt to the original cell/digit array
119
120 auto outputClustersTemp = mClusterizer.getFoundClusters();
121 auto outputCellDigitIndicesTemp = mClusterizer.getFoundClustersInputIndices();
122
123 std::copy(outputClustersTemp->begin(), outputClustersTemp->end(), std::back_inserter(outputClusters));
124 std::copy(outputCellDigitIndicesTemp->begin(), outputCellDigitIndicesTemp->end(), std::back_inserter(outputCellDigitIndices));
125
126 outputTriggerRecord.emplace_back(iTrgRcrd.getBCData(), currentStartClusters, outputClustersTemp->size());
127 outputTriggerRecordIndices.emplace_back(iTrgRcrd.getBCData(), currentStartIndices, outputCellDigitIndicesTemp->size());
128
129 currentStartClusters = outputClusters.size();
130 currentStartIndices = outputCellDigitIndices.size();
131 }
132
133 mEventHandler->setClusterData(outputClusters, outputCellDigitIndices, outputTriggerRecord, outputTriggerRecordIndices);
134 mEventHandler->setCellData(Inputs, InputTriggerRecord);
135
136 //for (const auto& inputEvent : mEventHandler) {
137 for (int iev = 0; iev < mEventHandler->getNumberOfEvents(); iev++) {
138 auto inputEvent = mEventHandler->buildEvent(iev);
139
140 mClusterFactory->reset();
141 mClusterFactory->setContainer(inputEvent.mClusters, Inputs, inputEvent.mCellIndices);
142
143 //for (const auto& analysisCluster : mClusterFactory) {
144 for (int icl = 0; icl < mClusterFactory->getNumberOfClusters(); icl++) {
145 auto analysisCluster = mClusterFactory->buildCluster(icl);
146 mOutputAnaClusters->push_back(analysisCluster);
147 }
148 }
149
150 LOG(debug) << "[EMCALClusterizer - run] Writing " << mOutputAnaClusters->size() << " clusters ...";
151 ctx.outputs().snapshot(o2::framework::Output{o2::header::gDataOriginEMC, "ANALYSISCLUSTERS", 0}, *mOutputAnaClusters);
152}
153
155{
156 std::vector<o2::framework::InputSpec> inputs;
157 std::vector<o2::framework::OutputSpec> outputs;
158
159 if (useDigits) {
160 inputs.emplace_back("digits", o2::header::gDataOriginEMC, "DIGITS", 0, o2::framework::Lifetime::Timeframe);
161 inputs.emplace_back("digitstrgr", o2::header::gDataOriginEMC, "DIGITSTRGR", 0, o2::framework::Lifetime::Timeframe);
162 } else {
163 inputs.emplace_back("cells", o2::header::gDataOriginEMC, "CELLS", 0, o2::framework::Lifetime::Timeframe);
164 inputs.emplace_back("cellstrgr", o2::header::gDataOriginEMC, "CELLSTRGR", 0, o2::framework::Lifetime::Timeframe);
165 }
166 auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(false, // orbitResetTime
167 false, // GRPECS=true
168 false, // GRPLHCIF
169 false, // GRPMagField
170 false, // askMatLUT
172 inputs,
173 true);
174
175 outputs.emplace_back(o2::header::gDataOriginEMC, "ANALYSISCLUSTERS", 0, o2::framework::Lifetime::Timeframe);
176
177 if (useDigits) {
178 return o2::framework::DataProcessorSpec{"EMCALAnalysisClusterSpec",
179 inputs,
180 outputs,
181 o2::framework::adaptFromTask<o2::emcal::reco_workflow::AnalysisClusterSpec<o2::emcal::Digit>>(ggRequest)};
182 } else {
183 return o2::framework::DataProcessorSpec{"EMCALAnalysisClusterSpec",
184 inputs,
185 outputs,
186 o2::framework::adaptFromTask<o2::emcal::reco_workflow::AnalysisClusterSpec<o2::emcal::Cell>>(ggRequest)};
187 }
188}
Definition of the GeometryManager class.
std::ostringstream debug
void checkUpdates(o2::framework::ProcessingContext &pc)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
EMCal clusters factory Ported from class AliEMCALcluster.
Handler for EMCAL event data.
Analysis Cluster task for EMCAL anlaysis clusters.
void run(framework::ProcessingContext &ctx) final
Run conversion of digits to cells.
void finaliseCCDB(framework::ConcreteDataMatcher &matcher, void *obj) final
void init(framework::InitContext &ctx) final
Initializing the AnalysisClusterSpec.
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 getAnalysisClusterSpec(bool useDigits)
Creating DataProcessorSpec for the EMCAL Analysis Cluster Spec.
constexpr o2::header::DataOrigin gDataOriginEMC
Definition DataHeader.h:565
std::vector< InputSpec > Inputs
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"