Skip to content

Commit c8953a1

Browse files
peressounkoDmitri Peresunko
andauthored
Bugfix in digits->raw->cell chain (#5087)
* MC labels treating fixed * Default file name set * raw digit creation fix * CarryOver and look fix * unique_ptr used * carryOver method restored to avoid RCU trailer splitting, time conversion sec-ns fixed Co-authored-by: Dmitri Peresunko <Dmitri.Peresunko@cern.ch>
1 parent 3034b64 commit c8953a1

22 files changed

Lines changed: 267 additions & 261 deletions

Detectors/PHOS/base/include/PHOSBase/Mapping.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ class Mapping
3838
kWrongAbsId,
3939
kWrongCaloFlag,
4040
kNotInitialized };
41-
static constexpr short NCHANNELS = 14337; ///< Number of channels starting from 1
42-
static constexpr short NHWPERDDL = 2048; ///< Number of HW addressed per DDL
43-
static constexpr short NDDL = 14; ///< Total number of DDLs
41+
static constexpr short NCHANNELS = 14337; ///< Number of channels starting from 1
42+
static constexpr short NHWPERDDL = 2048; ///< Number of HW addressed per DDL
43+
static constexpr short NMaxHWAddress = 3929; ///< Maximal HW address (size of array)
44+
static constexpr short NDDL = 14; ///< Total number of DDLs
4445

4546
enum CaloFlag { kHighGain,
4647
kLowGain,
@@ -69,12 +70,12 @@ class Mapping
6970
ErrorStatus constructAbsToHWMatrix();
7071

7172
private:
72-
std::string mPath = ""; ///< path to mapping files
73-
bool mInitialized = false; ///< If conversion tables created
74-
bool mInvInitialized = false; ///< If inverse conversion tables created
75-
short mAbsId[NDDL][NHWPERDDL] = {0}; ///< Conversion table (ddl,branch,fec,chip,channel) to absId
76-
CaloFlag mCaloFlag[NDDL][NHWPERDDL] = {kTRU}; ///< Conversion table (ddl,branch,fec,chip,channel) to absId
77-
short mAbsToHW[NCHANNELS][3][2] = {0}; ///< Conversion table (AbsId,caloFlag) to pair (ddl, hw address)
73+
std::string mPath = ""; ///< path to mapping files
74+
bool mInitialized = false; ///< If conversion tables created
75+
bool mInvInitialized = false; ///< If inverse conversion tables created
76+
short mAbsId[NDDL][NMaxHWAddress] = {0}; ///< Conversion table (ddl,branch,fec,chip,channel) to absId
77+
CaloFlag mCaloFlag[NDDL][NMaxHWAddress] = {kTRU}; ///< Conversion table (ddl,branch,fec,chip,channel) to absId
78+
short mAbsToHW[NCHANNELS][3][2] = {0}; ///< Conversion table (AbsId,caloFlag) to pair (ddl, hw address)
7879

7980
ClassDefNV(Mapping, 1);
8081
}; // End of Mapping

Detectors/PHOS/base/include/PHOSBase/PHOSSimParams.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,34 @@ struct PHOSSimParams : public o2::conf::ConfigurableParamHelper<PHOSSimParams> {
3535
bool mApplyNonLinearity = false; ///< Apply energy non-linearity in digitization
3636
bool mApplyDigitization = false; ///< Apply energy digitization in digitization
3737
float mAPDNoise = 0.005; ///< RMS of APD noise
38-
float mDigitThreshold = 2.5; ///< minimal energy to keep digit in ADC counts
38+
float mDigitThreshold = 2.; ///< minimal energy to keep digit in ADC counts
3939
float mADCwidth = 0.005; ///< width of ADC channel in GeV
4040
float mTOFa = 0.5e-9; ///< constant term of TOF resolution
4141
float mTOFb = 1.e-9; ///< stohastic term of TOF resolution
4242
float mCellNonLineaityA = 0.; ///< Amp of cel non-linearity
4343
float mCellNonLineaityB = 0.109; ///< Energy scale of cel non-linearity
4444
float mCellNonLineaityC = 1.; ///< Overall calibration
4545

46-
float mZSthreshold = 2.5; ///< Zero Suppression threshold
46+
short mZSthreshold = 1; ///< Zero Suppression threshold
4747
float mTimeResolutionA = 2.; ///< Time resolution parameter A (in ns)
4848
float mTimeResolutionB = 2.; ///< Time resolution parameter B (in ns/GeV)
4949
float mTimeResThreshold = 0.5; ///< threshold for time resolution calculation (in GeV)
5050
float mMinNoiseTime = -200.; ///< minimum time in noise channels (in ns)
5151
float mMaxNoiseTime = 2000.; ///< minimum time in noise channels (in ns)
5252

5353
//Parameters used in Raw simulation
54-
float mSampleDecayTime = 0.047619048; ///< Time parameter in Gamma2 function (1/tau, 100.e-9/2.1e-6)
54+
float mSampleDecayTime = 0.091; ///< Time parameter in Gamma2 function (1/tau, 100.e-9/2.1e-6)
5555

5656
// //Parameters used in raw data reconstruction
57+
short mSpikeThreshold = 100; ///< Single spike >100 ADC channels
58+
short mBaseLine = 0; ///<
59+
short mPreSamples = 2; ///< number of pre-samples readout before sample (if no pedestal subtrauction)
60+
short mMCOverflow = 970; ///< Overflow level for MC simulations: 1023-(pedestal~50)
61+
float mTimeTick = 100.; ///< ns to PHOS digitization step conversion
62+
5763
// bool mSubtractPedestal = false ; ///< subtract pedestals
5864
// bool mCreateSampleQualityOutput = false ; ///< Create stream of sample quality
5965
// bool mApplyBadMap = false ; ///< Apply bad map in sample fitting
60-
// short mZeroSuppression = 5; ///< Zero suppression in ADC counts
61-
// short mMaxSampleLength = 35; ///< Maximal length of sample
6266
// short mChiMinCut = 0 ; ///< Minimal cut on sample quality
6367
// short mChiMaxCut = 1000; ///< Maximal cut on sample quality
6468
// std::string mFitterVersion = "default"; ///< version of raw fitter to be used

Detectors/PHOS/base/include/PHOSBase/RCUTrailer.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ namespace o2
2323
namespace phos
2424
{
2525

26+
union ChannelHeader {
27+
uint32_t mDataWord;
28+
struct {
29+
uint32_t mHardwareAddress : 16; ///< Bits 0 - 15: Hardware address
30+
uint32_t mPayloadSize : 10; ///< Bits 16 - 25: Payload size
31+
uint32_t mZero1 : 3; ///< Bits 26 - 28: zeroed
32+
uint32_t mBadChannel : 1; ///< Bit 29: Bad channel status
33+
uint32_t mMark : 1; ///< Bits 30 - 30: Mark header
34+
};
35+
};
36+
37+
union CaloBunchWord {
38+
uint32_t mDataWord;
39+
struct {
40+
uint32_t mWord2 : 10; ///< Bits 0 - 9 : Word 2
41+
uint32_t mWord1 : 10; ///< Bits 10 - 19 : Word 1
42+
uint32_t mWord0 : 10; ///< Bits 20 - 29 : Word 0
43+
uint32_t mZero : 2; ///< Bits 30 - 31 : zeroed
44+
};
45+
};
46+
2647
/// \class RCUTrailer
2748
/// \brief Information stored in the RCU trailer
2849
/// \ingroup PHOSbase
@@ -74,6 +95,8 @@ class RCUTrailer
7495
/// \brief Constructor
7596
RCUTrailer() = default;
7697

98+
RCUTrailer(const gsl::span<const uint32_t> payloadwords);
99+
77100
/// \brief destructor
78101
~RCUTrailer() = default;
79102

Detectors/PHOS/base/src/Mapping.cxx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Mapping::ErrorStatus Mapping::hwToAbsId(short ddl, short hwAddr, short& absId, C
3535
if (ddl < 0 || ddl > 14) {
3636
return kWrongDDL;
3737
}
38-
if (hwAddr < 0 || hwAddr >= NHWPERDDL) {
38+
if (hwAddr < 0 || hwAddr >= NMaxHWAddress) {
3939
return kWrongHWAddress;
4040
}
4141

@@ -115,6 +115,10 @@ Mapping::ErrorStatus Mapping::setMapping()
115115
LOG(FATAL) << "Syntax of mapping file " << p << "/Mod" << m << "RCU" << i << ".data is wrong: no maxHWAddress";
116116
return kNotInitialized;
117117
}
118+
if (maxHWAddress > NMaxHWAddress) {
119+
LOG(FATAL) << "Maximal HW address in file " << maxHWAddress << "larger than array size " << NMaxHWAddress << "for /Mod" << m << "RCU" << i << ".data is wrong: no maxHWAddress";
120+
return kNotInitialized;
121+
}
118122

119123
for (short ich = 0; ich < numberOfChannels; ich++) { // 1792 = 2*896 channels connected to each RCU
120124
int hwAddress;
@@ -137,6 +141,10 @@ Mapping::ErrorStatus Mapping::setMapping()
137141
return kNotInitialized;
138142
}
139143

144+
if (caloFlag == 2) { //TODO!!!! TRU mapping not known yet
145+
continue;
146+
}
147+
140148
//convert ddl, col,raw caloFlag to AbsId
141149
// Converts the absolute numbering into the following array
142150
// relid[0] = PHOS Module number

Detectors/PHOS/base/src/RCUTrailer.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
using namespace o2::phos;
1818

19+
RCUTrailer::RCUTrailer(const gsl::span<const uint32_t> payloadwords)
20+
{
21+
constructFromRawPayload(payloadwords);
22+
}
23+
1924
void RCUTrailer::reset()
2025
{
2126
mRCUId = -1;

Detectors/PHOS/reconstruction/include/PHOSReconstruction/AltroDecoder.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ class AltroDecoder
100100
AltroDecoderError::ErrorType_t decode();
101101

102102
/// \brief Get reference to the RCU trailer object
103-
/// \return const reference to the RCU trailer
104-
/// \throw AltroDecoderError with type RCU_TRAILER_ERROR if the RCU trailer was not initialized
105-
const RCUTrailer& getRCUTrailer() const;
103+
/// \return reference to the RCU trailers vector
104+
const RCUTrailer& getRCUTrailer() const { return mRCUTrailer; }
106105

107106
/// \brief Get the reference to the channel container
108107
/// \return Reference to the channel container

Detectors/PHOS/reconstruction/include/PHOSReconstruction/RawPayload.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class RawPayload
7474

7575
/// \brief Get the size of the payload
7676
/// \return Size of the payload
77-
int getPayloadSize() const { return mPayloadWords.size() * sizeof(uint32_t); }
77+
int getPayloadSize() const { return mPayloadWords.size(); }
7878

7979
private:
8080
std::vector<uint32_t> mPayloadWords; ///< Payload words (excluding raw header)

Detectors/PHOS/reconstruction/include/PHOSReconstruction/RawReaderMemory.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,6 @@ class RawReaderMemory
6060
/// it should not be called directly by the user.
6161
void nextPage(bool resetPayload = true);
6262

63-
/// \brief Read page with a given index
64-
/// \param page Index of the page to be decoded
65-
/// \throw RawDecodingError if the page cannot be read or header or payload cannot be deocded
66-
///
67-
/// The reader will try to read the page with a certain index. In
68-
/// case the page cannot be decoded (page index outside range,
69-
/// decoding of header or payload failed), and excpetion is raised.
70-
void readPage(int page);
71-
7263
/// \brief access to the raw header of the current page
7364
/// \return Raw header of the current page
7465
/// \throw RawDecodingError with HEADER_INVALID if the header was not decoded

Detectors/PHOS/reconstruction/run/rawReaderFile.cxx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ int main(int argc, char** argv)
100100
o2::phos::AltroDecoder decoder(parser);
101101
decoder.decode();
102102

103-
std::cout << decoder.getRCUTrailer() << std::endl;
104-
for (auto& chan : decoder.getChannels()) {
103+
auto& rcu = decoder.getRCUTrailer();
104+
auto& channellist = decoder.getChannels();
105+
std::cout << rcu << std::endl;
106+
for (auto& chan : channellist) {
105107
std::cout << "Hw address: " << chan.getHardwareAddress() << std::endl;
106108
for (auto& bunch : chan.getBunches()) {
107109
std::cout << "BunchLength: " << int(bunch.getBunchLength()) << std::endl;

Detectors/PHOS/reconstruction/src/AltroDecoder.cxx

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "InfoLogger/InfoLogger.hxx"
1313
#include "PHOSReconstruction/AltroDecoder.h"
1414
#include "PHOSReconstruction/RawReaderMemory.h"
15+
#include "PHOSReconstruction/RawDecodingError.h"
1516

1617
#include "DetectorsRaw/RDHUtils.h"
1718
#include <FairLogger.h>
@@ -46,9 +47,9 @@ AltroDecoderError::ErrorType_t AltroDecoder::decode()
4647
void AltroDecoder::readRCUTrailer()
4748
{
4849
try {
49-
auto payloadwordsOrig = mRawReader.getPayload().getPayloadWords();
50-
gsl::span<const uint32_t> payloadwords(payloadwordsOrig.data(), payloadwordsOrig.size());
51-
mRCUTrailer.constructFromRawPayload(payloadwords);
50+
auto payloadwords = mRawReader.getPayload().getPayloadWords();
51+
gsl::span<const uint32_t> tmp(payloadwords.data(), payloadwords.size());
52+
mRCUTrailer.constructFromRawPayload(tmp);
5253
} catch (RCUTrailer::Error& e) {
5354
throw e;
5455
}
@@ -64,13 +65,18 @@ void AltroDecoder::readChannels()
6465
mChannels.clear();
6566
int currentpos = 0;
6667
auto& buffer = mRawReader.getPayload().getPayloadWords();
67-
while (currentpos < buffer.size() - mRCUTrailer.getTrailerSize()) {
68+
69+
int payloadend = mRCUTrailer.getPayloadSize();
70+
while (currentpos < payloadend) {
6871
auto currentword = buffer[currentpos++];
69-
if (currentword >> 30 != 1) {
72+
ChannelHeader header = {currentword};
73+
74+
if (header.mMark != 1) {
75+
LOG(ERROR) << "Channel header mark not found";
7076
continue;
7177
}
7278
// starting a new channel
73-
mChannels.emplace_back(currentword & 0xFFF, (currentword >> 16) & 0x3FF);
79+
mChannels.emplace_back(int(header.mHardwareAddress), int(header.mPayloadSize));
7480
auto& currentchannel = mChannels.back();
7581
/// decode all words for channel
7682
int numberofwords = (currentchannel.getPayloadSize() + 2) / 3;
@@ -101,18 +107,9 @@ void AltroDecoder::readChannels()
101107
mChannelsInitialized = true;
102108
}
103109

104-
const RCUTrailer& AltroDecoder::getRCUTrailer() const
105-
{
106-
if (!mRCUTrailer.isInitialized()) {
107-
throw AltroDecoderError::ErrorType_t::RCU_TRAILER_ERROR; // "RCU trailer was not initialized");
108-
}
109-
return mRCUTrailer;
110-
}
111-
112110
const std::vector<Channel>& AltroDecoder::getChannels() const
113111
{
114-
if (!mChannelsInitialized) {
112+
if (!mChannelsInitialized)
115113
throw AltroDecoderError::ErrorType_t::CHANNEL_ERROR; // "Channels not initizalized");
116-
}
117114
return mChannels;
118115
}

0 commit comments

Comments
 (0)