Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class CaloFitResults
/// \brief Default constructor
CaloFitResults() = default;

/// \brief copy constructor
CaloFitResults(const CaloFitResults& fitresults) = default;

/// \brief Assignment operator
CaloFitResults& operator=(const CaloFitResults& source);

/// \brief Constructor for recording all the fit parameters
explicit CaloFitResults(unsigned short maxSig,
float ped,
Expand All @@ -62,22 +68,31 @@ class CaloFitResults
/// \brief minimum interface
explicit CaloFitResults(int maxSig, int minSig);

/// \brief Comparison of two fit results
bool operator==(const CaloFitResults& other) const;

~CaloFitResults() = default;

void setMaxSig(unsigned short maxSig) { mMaxSig = maxSig; }
void setPed(float ped) { mPed = ped; }
void setMinSig(unsigned short minSig) { mMinSig = minSig; }
void setStatus(int status) { mStatus = status; }
void setTime(float time) { mTime = time; }
void setAmp(float amp) { mAmpSig = amp; }
void setMaxTimeBin(int timebin) { mMaxTimebin = timebin; }
void setChi2(float chi2) { mChi2Sig = chi2; }
void setNdf(unsigned short ndf) { mNdfSig = ndf; }

unsigned short getMaxSig() const { return mMaxSig; }
float getPed() const { return mPed; }
unsigned short getMinSig() const { return mMinSig; }
int getStatus() const { return mStatus; }
float getAmp() const { return mAmpSig; }
float getMaxTimeBin() const { return mMaxTimebin; }
double getTime() const { return mTime; }
int getMaxTimebin() const { return mMaxTimebin; }
int getMaxTimeBin() const { return mMaxTimebin; }
float getChi2() const { return mChi2Sig; }
unsigned short getNdf() const { return mNdfSig; }

void setTime(float time) { mTime = time; }
void setAmp(float amp) { mAmpSig = amp; }

private:
unsigned short mMaxSig = 0; ///< Maximum sample value ( 0 - 1023 )
float mPed = -1; ///< Pedestal
Expand Down
29 changes: 24 additions & 5 deletions Detectors/EMCAL/reconstruction/src/CaloFitResults.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ CaloFitResults::CaloFitResults(unsigned short maxSig, float ped,
{
}

///\brief Constructor, shorter interface when no fit is done
//_____________________________________________________________________
CaloFitResults::CaloFitResults(unsigned short maxSig, float ped,
int fitstatus, float amp,
int maxTimebin) : mMaxSig(maxSig),
Expand All @@ -47,10 +45,31 @@ CaloFitResults::CaloFitResults(unsigned short maxSig, float ped,
{
}

///
/// Constructor, minimal interface
//_____________________________________________________________________
CaloFitResults::CaloFitResults(int maxSig, int minSig) : mMaxSig(maxSig),
mMinSig(minSig)
{
}

CaloFitResults& CaloFitResults::operator=(const CaloFitResults& source)
{
if (this != &source) {
mMaxSig = source.mMaxSig;
mPed = source.mPed;
mStatus = source.mStatus;
mAmpSig = source.mAmpSig;
mTime = source.mTime;
mMaxTimebin = source.mMaxTimebin;
mChi2Sig = source.mChi2Sig;
mNdfSig = source.mNdfSig;
mMinSig = source.mMinSig;
}
return *this;
}

bool CaloFitResults::operator==(const CaloFitResults& other) const
{
return (mMaxSig == other.mMaxSig) && (mPed == other.mPed) &&
(mStatus == other.mStatus) && (mAmpSig == other.mAmpSig) && (mTime == other.mTime) &&
(mMaxTimebin == other.mMaxTimebin) && (mChi2Sig == other.mChi2Sig) &&
(mNdfSig == other.mNdfSig) && (mMinSig == other.mMinSig);
}
2 changes: 1 addition & 1 deletion Detectors/EMCAL/reconstruction/src/CaloRawFitter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ std::tuple<int, int, float, short, short, float, int, int> CaloRawFitter::preFit
int length = bunchvector.at(index).getBunchLength();
const std::vector<uint16_t>& sig = bunchvector.at(index).getADC();

double ped = evaluatePedestal(sig, length);
ped = evaluatePedestal(sig, length);

for (int i = 0; i < length; i++) {
mReversed[i] = sig[length - i - 1] - ped;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ CaloFitResults CaloRawFitterStandard::evaluate(const std::vector<Bunch>& bunchli
time = time * constants::EMCAL_TIMESAMPLE;
time -= mL1Phase;

return CaloFitResults(-99, pedEstimate, mAlgo, amp, time, (int)time, chi2, ndf);
return CaloFitResults(maxADC, pedEstimate, mAlgo, amp, time, (int)time, chi2, ndf);
}
return CaloFitResults(-1, -1);
}
Expand Down
1 change: 1 addition & 0 deletions Detectors/EMCAL/workflow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ o2_add_library(EMCALWorkflow
src/ClusterizerSpec.cxx
src/DigitsPrinterSpec.cxx
src/AnalysisClusterSpec.cxx
src/RawToCellConverterSpec.cxx
PUBLIC_LINK_LIBRARIES O2::Framework O2::DataFormatsEMCAL
O2::DPLUtils O2::EMCALBase O2::EMCALReconstruction O2::Algorithm)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#include <vector>

#include "DataFormatsEMCAL/Cell.h"
#include "Framework/DataProcessorSpec.h"
#include "Framework/Task.h"
#include "EMCALBase/Geometry.h"
#include "EMCALBase/Mapper.h"
#include "DataFormatsEMCAL/TriggerRecord.h"
#include "EMCALReconstruction/CaloRawFitterStandard.h"

namespace o2
{

namespace emcal
{

namespace reco_workflow
{

/// \class RawToCellConverterSpec
/// \brief Coverter task for Raw data to EMCAL cells
/// \author Hadi Hassan <hadi.hassan@cern.ch>, Oak Ridge National Laboratory
/// \since December 10, 2019
///
class RawToCellConverterSpec : public framework::Task
{
public:
/// \brief Constructor
/// \param propagateMC If true the MCTruthContainer is propagated to the output
RawToCellConverterSpec() : framework::Task(){};

/// \brief Destructor
~RawToCellConverterSpec() override = default;

/// \brief Initializing the RawToCellConverterSpec
/// \param ctx Init context
void init(framework::InitContext& ctx) final;

/// \brief Run conversion of raw data to cells
/// \param ctx Processing context
///
/// The following branches are linked:
/// Input RawData: {"ROUT", "RAWDATA", 0, Lifetime::Timeframe}
/// Output cells: {"EMC", "CELLS", 0, Lifetime::Timeframe}
/// Output cells trigger record: {"EMC", "CELLSTR", 0, Lifetime::Timeframe}
void run(framework::ProcessingContext& ctx) final;

void setNoiseThreshold(int thresold) { mNoiseThreshold = thresold; }
int getNoiseThreshold() { return mNoiseThreshold; }

private:
int mNoiseThreshold = 0;
o2::emcal::Geometry* mGeometry = nullptr; ///!<! Geometry pointer
std::unique_ptr<o2::emcal::MappingHandler> mMapper = nullptr; ///!<! Mapper
o2::emcal::CaloRawFitterStandard mRawFitter; ///!<! Raw fitter
std::vector<o2::emcal::Cell> mOutputCells; ///< Container with output cells
std::vector<o2::emcal::TriggerRecord> mOutputTriggerRecords; ///< Container with output cells
};

/// \brief Creating DataProcessorSpec for the EMCAL Cell Converter Spec
///
/// Refer to RawToCellConverterSpec::run for input and output specs
framework::DataProcessorSpec getRawToCellConverterSpec();

} // namespace reco_workflow

} // namespace emcal

} // namespace o2
142 changes: 142 additions & 0 deletions Detectors/EMCAL/workflow/src/RawToCellConverterSpec.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include "FairLogger.h"

#include "DataFormatsEMCAL/EMCALBlockHeader.h"
#include "DataFormatsEMCAL/TriggerRecord.h"
#include "EMCALWorkflow/RawToCellConverterSpec.h"
#include "Framework/ControlService.h"
#include "SimulationDataFormat/MCCompLabel.h"
#include "SimulationDataFormat/MCTruthContainer.h"
#include "EMCALBase/Geometry.h"
#include "EMCALBase/Mapper.h"
#include "EMCALReconstruction/CaloFitResults.h"
#include "EMCALReconstruction/Bunch.h"
#include "EMCALReconstruction/CaloRawFitterStandard.h"
#include "EMCALReconstruction/AltroDecoder.h"
#include "CommonDataFormat/InteractionRecord.h"

using namespace o2::emcal::reco_workflow;

void RawToCellConverterSpec::init(framework::InitContext& ctx)
{
LOG(DEBUG) << "[EMCALRawToCellConverter - init] Initialize converter ";
if (!mGeometry) {
mGeometry = o2::emcal::Geometry::GetInstanceFromRunNumber(223409);
}
if (!mGeometry)
LOG(ERROR) << "Failure accessing geometry";

if (!mMapper) {
mMapper = std::unique_ptr<o2::emcal::MappingHandler>(new o2::emcal::MappingHandler);
}
if (!mMapper)
LOG(ERROR) << "Failed to initialize mapper";

mRawFitter.setAmpCut(mNoiseThreshold);
mRawFitter.setL1Phase(0.);
}

void RawToCellConverterSpec::run(framework::ProcessingContext& ctx)
{
LOG(DEBUG) << "[EMCALRawToCellConverter - run] called";

mOutputCells.clear();
mOutputTriggerRecords.clear();

int firstEntry = 0;
for (const auto& rawData : ctx.inputs()) {

//o2::emcal::RawReaderMemory<o2::header::RAWDataHeaderV4> rawreader(gsl::span(rawData.payload, o2::framework::DataRefUtils::getPayloadSize(rawData)));

o2::emcal::RawReaderMemory<o2::header::RAWDataHeaderV4> rawreader(o2::framework::DataRefUtils::as<const char>(rawData));

bool first = true;
uint16_t currentTrigger = 0;
uint32_t currentorbit = 0;

// loop over all the DMA pages
while (rawreader.hasNext()) {

rawreader.next();

auto header = rawreader.getRawHeader();

if (!first) { // check if it is the first event in the payload
std::cout << " triggerBC " << header.triggerBC << " current Trigger " << currentTrigger << std::endl;
if (header.triggerBC > currentTrigger) { //new event
mOutputTriggerRecords.emplace_back(o2::InteractionRecord(currentTrigger, currentorbit), firstEntry, mOutputCells.size() - 1);
firstEntry = mOutputCells.size();

currentTrigger = header.triggerBC;
currentorbit = header.triggerOrbit;
} //new event
} else { //first
currentTrigger = header.triggerBC;
std::cout << " first is true and I set triggerBC to currentTrigger " << currentTrigger << std::endl;
currentorbit = header.triggerOrbit;
std::cout << " and set first to false " << std::endl;
first = false;
}

if (header.feeId > 40)
continue; //skip STU ddl

//std::cout<<rawreader.getRawHeader()<<std::endl;

// use the altro decoder to decode the raw data, and extract the RCU trailer
o2::emcal::AltroDecoder<decltype(rawreader)> decoder(rawreader);
decoder.decode();

std::cout << decoder.getRCUTrailer() << std::endl;

o2::emcal::Mapper map = mMapper->getMappingForDDL(header.feeId);

// Loop over all the channels
for (auto& chan : decoder.getChannels()) {

int iRow = map.getRow(chan.getHardwareAddress());
int iCol = map.getColumn(chan.getHardwareAddress());
ChannelType_t chantype = map.getChannelType(chan.getHardwareAddress());
int iSM = header.feeId / 2;

int CellID = mGeometry->GetAbsCellIdFromCellIndexes(iSM, iRow, iCol);

// define the conatiner for the fit results, and perform the raw fitting using the stadnard raw fitter
o2::emcal::CaloFitResults fitResults = mRawFitter.evaluate(chan.getBunches(), 0, 0);

if (fitResults.getAmp() < 0 && fitResults.getTime() < 0) {
fitResults.setAmp(0.);
fitResults.setTime(0.);
}
mOutputCells.emplace_back(CellID, fitResults.getAmp(), fitResults.getTime(), chantype);
}
}
}

LOG(DEBUG) << "[EMCALRawToCellConverter - run] Writing " << mOutputCells.size() << " cells ...";
ctx.outputs().snapshot(o2::framework::Output{"EMC", "CELLS", 0, o2::framework::Lifetime::Timeframe}, mOutputCells);
ctx.outputs().snapshot(o2::framework::Output{"EMC", "CELLSTRGR", 0, o2::framework::Lifetime::Timeframe}, mOutputTriggerRecords);
}

o2::framework::DataProcessorSpec o2::emcal::reco_workflow::getRawToCellConverterSpec()
{
std::vector<o2::framework::InputSpec> inputs;
std::vector<o2::framework::OutputSpec> outputs;

inputs.emplace_back("readout-proxy", "FLP", "RAWDATA", 0, o2::framework::Lifetime::Timeframe);
outputs.emplace_back("EMC", "CELLS", 0, o2::framework::Lifetime::Timeframe);
outputs.emplace_back("EMC", "CELLSTRGR", 0, o2::framework::Lifetime::Timeframe);

return o2::framework::DataProcessorSpec{"EMCALRawToCellConverterSpec",
inputs,
outputs,
o2::framework::adaptFromTask<o2::emcal::reco_workflow::RawToCellConverterSpec>()};
}
Loading