Skip to content

Commit fe27669

Browse files
authored
[EMCAL-630] DPL component for Raw to Cell conversion (#3079)
-DPL component for Raw to Cell conversion
1 parent 99c816d commit fe27669

File tree

8 files changed

+299
-13
lines changed

8 files changed

+299
-13
lines changed

Detectors/EMCAL/reconstruction/include/EMCALReconstruction/CaloFitResults.h

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ class CaloFitResults
4141
/// \brief Default constructor
4242
CaloFitResults() = default;
4343

44+
/// \brief copy constructor
45+
CaloFitResults(const CaloFitResults& fitresults) = default;
46+
47+
/// \brief Assignment operator
48+
CaloFitResults& operator=(const CaloFitResults& source);
49+
4450
/// \brief Constructor for recording all the fit parameters
4551
explicit CaloFitResults(unsigned short maxSig,
4652
float ped,
@@ -62,22 +68,31 @@ class CaloFitResults
6268
/// \brief minimum interface
6369
explicit CaloFitResults(int maxSig, int minSig);
6470

71+
/// \brief Comparison of two fit results
72+
bool operator==(const CaloFitResults& other) const;
73+
6574
~CaloFitResults() = default;
6675

76+
void setMaxSig(unsigned short maxSig) { mMaxSig = maxSig; }
77+
void setPed(float ped) { mPed = ped; }
78+
void setMinSig(unsigned short minSig) { mMinSig = minSig; }
79+
void setStatus(int status) { mStatus = status; }
80+
void setTime(float time) { mTime = time; }
81+
void setAmp(float amp) { mAmpSig = amp; }
82+
void setMaxTimeBin(int timebin) { mMaxTimebin = timebin; }
83+
void setChi2(float chi2) { mChi2Sig = chi2; }
84+
void setNdf(unsigned short ndf) { mNdfSig = ndf; }
85+
6786
unsigned short getMaxSig() const { return mMaxSig; }
6887
float getPed() const { return mPed; }
6988
unsigned short getMinSig() const { return mMinSig; }
7089
int getStatus() const { return mStatus; }
7190
float getAmp() const { return mAmpSig; }
72-
float getMaxTimeBin() const { return mMaxTimebin; }
7391
double getTime() const { return mTime; }
74-
int getMaxTimebin() const { return mMaxTimebin; }
92+
int getMaxTimeBin() const { return mMaxTimebin; }
7593
float getChi2() const { return mChi2Sig; }
7694
unsigned short getNdf() const { return mNdfSig; }
7795

78-
void setTime(float time) { mTime = time; }
79-
void setAmp(float amp) { mAmpSig = amp; }
80-
8196
private:
8297
unsigned short mMaxSig = 0; ///< Maximum sample value ( 0 - 1023 )
8398
float mPed = -1; ///< Pedestal

Detectors/EMCAL/reconstruction/src/CaloFitResults.cxx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ CaloFitResults::CaloFitResults(unsigned short maxSig, float ped,
3434
{
3535
}
3636

37-
///\brief Constructor, shorter interface when no fit is done
38-
//_____________________________________________________________________
3937
CaloFitResults::CaloFitResults(unsigned short maxSig, float ped,
4038
int fitstatus, float amp,
4139
int maxTimebin) : mMaxSig(maxSig),
@@ -47,10 +45,31 @@ CaloFitResults::CaloFitResults(unsigned short maxSig, float ped,
4745
{
4846
}
4947

50-
///
51-
/// Constructor, minimal interface
52-
//_____________________________________________________________________
5348
CaloFitResults::CaloFitResults(int maxSig, int minSig) : mMaxSig(maxSig),
5449
mMinSig(minSig)
5550
{
5651
}
52+
53+
CaloFitResults& CaloFitResults::operator=(const CaloFitResults& source)
54+
{
55+
if (this != &source) {
56+
mMaxSig = source.mMaxSig;
57+
mPed = source.mPed;
58+
mStatus = source.mStatus;
59+
mAmpSig = source.mAmpSig;
60+
mTime = source.mTime;
61+
mMaxTimebin = source.mMaxTimebin;
62+
mChi2Sig = source.mChi2Sig;
63+
mNdfSig = source.mNdfSig;
64+
mMinSig = source.mMinSig;
65+
}
66+
return *this;
67+
}
68+
69+
bool CaloFitResults::operator==(const CaloFitResults& other) const
70+
{
71+
return (mMaxSig == other.mMaxSig) && (mPed == other.mPed) &&
72+
(mStatus == other.mStatus) && (mAmpSig == other.mAmpSig) && (mTime == other.mTime) &&
73+
(mMaxTimebin == other.mMaxTimebin) && (mChi2Sig == other.mChi2Sig) &&
74+
(mNdfSig == other.mNdfSig) && (mMinSig == other.mMinSig);
75+
}

Detectors/EMCAL/reconstruction/src/CaloRawFitter.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ std::tuple<int, int, float, short, short, float, int, int> CaloRawFitter::preFit
262262
int length = bunchvector.at(index).getBunchLength();
263263
const std::vector<uint16_t>& sig = bunchvector.at(index).getADC();
264264

265-
double ped = evaluatePedestal(sig, length);
265+
ped = evaluatePedestal(sig, length);
266266

267267
for (int i = 0; i < length; i++) {
268268
mReversed[i] = sig[length - i - 1] - ped;

Detectors/EMCAL/reconstruction/src/CaloRawFitterStandard.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ CaloFitResults CaloRawFitterStandard::evaluate(const std::vector<Bunch>& bunchli
9292
time = time * constants::EMCAL_TIMESAMPLE;
9393
time -= mL1Phase;
9494

95-
return CaloFitResults(-99, pedEstimate, mAlgo, amp, time, (int)time, chi2, ndf);
95+
return CaloFitResults(maxADC, pedEstimate, mAlgo, amp, time, (int)time, chi2, ndf);
9696
}
9797
return CaloFitResults(-1, -1);
9898
}

Detectors/EMCAL/workflow/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ o2_add_library(EMCALWorkflow
1515
src/ClusterizerSpec.cxx
1616
src/DigitsPrinterSpec.cxx
1717
src/AnalysisClusterSpec.cxx
18+
src/RawToCellConverterSpec.cxx
1819
PUBLIC_LINK_LIBRARIES O2::Framework O2::DataFormatsEMCAL
1920
O2::DPLUtils O2::EMCALBase O2::EMCALReconstruction O2::Algorithm)
2021

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#include <vector>
12+
13+
#include "DataFormatsEMCAL/Cell.h"
14+
#include "Framework/DataProcessorSpec.h"
15+
#include "Framework/Task.h"
16+
#include "EMCALBase/Geometry.h"
17+
#include "EMCALBase/Mapper.h"
18+
#include "DataFormatsEMCAL/TriggerRecord.h"
19+
#include "EMCALReconstruction/CaloRawFitterStandard.h"
20+
21+
namespace o2
22+
{
23+
24+
namespace emcal
25+
{
26+
27+
namespace reco_workflow
28+
{
29+
30+
/// \class RawToCellConverterSpec
31+
/// \brief Coverter task for Raw data to EMCAL cells
32+
/// \author Hadi Hassan <hadi.hassan@cern.ch>, Oak Ridge National Laboratory
33+
/// \since December 10, 2019
34+
///
35+
class RawToCellConverterSpec : public framework::Task
36+
{
37+
public:
38+
/// \brief Constructor
39+
/// \param propagateMC If true the MCTruthContainer is propagated to the output
40+
RawToCellConverterSpec() : framework::Task(){};
41+
42+
/// \brief Destructor
43+
~RawToCellConverterSpec() override = default;
44+
45+
/// \brief Initializing the RawToCellConverterSpec
46+
/// \param ctx Init context
47+
void init(framework::InitContext& ctx) final;
48+
49+
/// \brief Run conversion of raw data to cells
50+
/// \param ctx Processing context
51+
///
52+
/// The following branches are linked:
53+
/// Input RawData: {"ROUT", "RAWDATA", 0, Lifetime::Timeframe}
54+
/// Output cells: {"EMC", "CELLS", 0, Lifetime::Timeframe}
55+
/// Output cells trigger record: {"EMC", "CELLSTR", 0, Lifetime::Timeframe}
56+
void run(framework::ProcessingContext& ctx) final;
57+
58+
void setNoiseThreshold(int thresold) { mNoiseThreshold = thresold; }
59+
int getNoiseThreshold() { return mNoiseThreshold; }
60+
61+
private:
62+
int mNoiseThreshold = 0;
63+
o2::emcal::Geometry* mGeometry = nullptr; ///!<! Geometry pointer
64+
std::unique_ptr<o2::emcal::MappingHandler> mMapper = nullptr; ///!<! Mapper
65+
o2::emcal::CaloRawFitterStandard mRawFitter; ///!<! Raw fitter
66+
std::vector<o2::emcal::Cell> mOutputCells; ///< Container with output cells
67+
std::vector<o2::emcal::TriggerRecord> mOutputTriggerRecords; ///< Container with output cells
68+
};
69+
70+
/// \brief Creating DataProcessorSpec for the EMCAL Cell Converter Spec
71+
///
72+
/// Refer to RawToCellConverterSpec::run for input and output specs
73+
framework::DataProcessorSpec getRawToCellConverterSpec();
74+
75+
} // namespace reco_workflow
76+
77+
} // namespace emcal
78+
79+
} // namespace o2
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
#include "FairLogger.h"
11+
12+
#include "DataFormatsEMCAL/EMCALBlockHeader.h"
13+
#include "DataFormatsEMCAL/TriggerRecord.h"
14+
#include "EMCALWorkflow/RawToCellConverterSpec.h"
15+
#include "Framework/ControlService.h"
16+
#include "SimulationDataFormat/MCCompLabel.h"
17+
#include "SimulationDataFormat/MCTruthContainer.h"
18+
#include "EMCALBase/Geometry.h"
19+
#include "EMCALBase/Mapper.h"
20+
#include "EMCALReconstruction/CaloFitResults.h"
21+
#include "EMCALReconstruction/Bunch.h"
22+
#include "EMCALReconstruction/CaloRawFitterStandard.h"
23+
#include "EMCALReconstruction/AltroDecoder.h"
24+
#include "CommonDataFormat/InteractionRecord.h"
25+
26+
using namespace o2::emcal::reco_workflow;
27+
28+
void RawToCellConverterSpec::init(framework::InitContext& ctx)
29+
{
30+
LOG(DEBUG) << "[EMCALRawToCellConverter - init] Initialize converter ";
31+
if (!mGeometry) {
32+
mGeometry = o2::emcal::Geometry::GetInstanceFromRunNumber(223409);
33+
}
34+
if (!mGeometry)
35+
LOG(ERROR) << "Failure accessing geometry";
36+
37+
if (!mMapper) {
38+
mMapper = std::unique_ptr<o2::emcal::MappingHandler>(new o2::emcal::MappingHandler);
39+
}
40+
if (!mMapper)
41+
LOG(ERROR) << "Failed to initialize mapper";
42+
43+
mRawFitter.setAmpCut(mNoiseThreshold);
44+
mRawFitter.setL1Phase(0.);
45+
}
46+
47+
void RawToCellConverterSpec::run(framework::ProcessingContext& ctx)
48+
{
49+
LOG(DEBUG) << "[EMCALRawToCellConverter - run] called";
50+
51+
mOutputCells.clear();
52+
mOutputTriggerRecords.clear();
53+
54+
int firstEntry = 0;
55+
for (const auto& rawData : ctx.inputs()) {
56+
57+
//o2::emcal::RawReaderMemory<o2::header::RAWDataHeaderV4> rawreader(gsl::span(rawData.payload, o2::framework::DataRefUtils::getPayloadSize(rawData)));
58+
59+
o2::emcal::RawReaderMemory<o2::header::RAWDataHeaderV4> rawreader(o2::framework::DataRefUtils::as<const char>(rawData));
60+
61+
bool first = true;
62+
uint16_t currentTrigger = 0;
63+
uint32_t currentorbit = 0;
64+
65+
// loop over all the DMA pages
66+
while (rawreader.hasNext()) {
67+
68+
rawreader.next();
69+
70+
auto header = rawreader.getRawHeader();
71+
72+
if (!first) { // check if it is the first event in the payload
73+
std::cout << " triggerBC " << header.triggerBC << " current Trigger " << currentTrigger << std::endl;
74+
if (header.triggerBC > currentTrigger) { //new event
75+
mOutputTriggerRecords.emplace_back(o2::InteractionRecord(currentTrigger, currentorbit), firstEntry, mOutputCells.size() - 1);
76+
firstEntry = mOutputCells.size();
77+
78+
currentTrigger = header.triggerBC;
79+
currentorbit = header.triggerOrbit;
80+
} //new event
81+
} else { //first
82+
currentTrigger = header.triggerBC;
83+
std::cout << " first is true and I set triggerBC to currentTrigger " << currentTrigger << std::endl;
84+
currentorbit = header.triggerOrbit;
85+
std::cout << " and set first to false " << std::endl;
86+
first = false;
87+
}
88+
89+
if (header.feeId > 40)
90+
continue; //skip STU ddl
91+
92+
//std::cout<<rawreader.getRawHeader()<<std::endl;
93+
94+
// use the altro decoder to decode the raw data, and extract the RCU trailer
95+
o2::emcal::AltroDecoder<decltype(rawreader)> decoder(rawreader);
96+
decoder.decode();
97+
98+
std::cout << decoder.getRCUTrailer() << std::endl;
99+
100+
o2::emcal::Mapper map = mMapper->getMappingForDDL(header.feeId);
101+
102+
// Loop over all the channels
103+
for (auto& chan : decoder.getChannels()) {
104+
105+
int iRow = map.getRow(chan.getHardwareAddress());
106+
int iCol = map.getColumn(chan.getHardwareAddress());
107+
ChannelType_t chantype = map.getChannelType(chan.getHardwareAddress());
108+
int iSM = header.feeId / 2;
109+
110+
int CellID = mGeometry->GetAbsCellIdFromCellIndexes(iSM, iRow, iCol);
111+
112+
// define the conatiner for the fit results, and perform the raw fitting using the stadnard raw fitter
113+
o2::emcal::CaloFitResults fitResults = mRawFitter.evaluate(chan.getBunches(), 0, 0);
114+
115+
if (fitResults.getAmp() < 0 && fitResults.getTime() < 0) {
116+
fitResults.setAmp(0.);
117+
fitResults.setTime(0.);
118+
}
119+
mOutputCells.emplace_back(CellID, fitResults.getAmp(), fitResults.getTime(), chantype);
120+
}
121+
}
122+
}
123+
124+
LOG(DEBUG) << "[EMCALRawToCellConverter - run] Writing " << mOutputCells.size() << " cells ...";
125+
ctx.outputs().snapshot(o2::framework::Output{"EMC", "CELLS", 0, o2::framework::Lifetime::Timeframe}, mOutputCells);
126+
ctx.outputs().snapshot(o2::framework::Output{"EMC", "CELLSTRGR", 0, o2::framework::Lifetime::Timeframe}, mOutputTriggerRecords);
127+
}
128+
129+
o2::framework::DataProcessorSpec o2::emcal::reco_workflow::getRawToCellConverterSpec()
130+
{
131+
std::vector<o2::framework::InputSpec> inputs;
132+
std::vector<o2::framework::OutputSpec> outputs;
133+
134+
inputs.emplace_back("readout-proxy", "FLP", "RAWDATA", 0, o2::framework::Lifetime::Timeframe);
135+
outputs.emplace_back("EMC", "CELLS", 0, o2::framework::Lifetime::Timeframe);
136+
outputs.emplace_back("EMC", "CELLSTRGR", 0, o2::framework::Lifetime::Timeframe);
137+
138+
return o2::framework::DataProcessorSpec{"EMCALRawToCellConverterSpec",
139+
inputs,
140+
outputs,
141+
o2::framework::adaptFromTask<o2::emcal::reco_workflow::RawToCellConverterSpec>()};
142+
}

0 commit comments

Comments
 (0)