Skip to content

Commit 0748bbb

Browse files
mbroz84shahor02
andauthored
Fixed of FDD digit2raw and digit writer/reader (#5617)
* Fixed of FDD digit2raw and digit writer/reader * disable MC in DigitWriter/Reader when used with raw data * Fixes in digit inconsistency * clang format * Data type mismatch * Data type mismatch * Data type mismatch Co-authored-by: shahoian <ruben.shahoyan@cern.ch>
1 parent a4cc067 commit 0748bbb

File tree

16 files changed

+195
-202
lines changed

16 files changed

+195
-202
lines changed

DataFormats/Detectors/FIT/FDD/include/DataFormatsFDD/ChannelData.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ namespace fdd
2525

2626
struct ChannelData {
2727

28-
int mPMNumber = -1; // PhotoMultiplier number (0 to 16)
29-
float mTime = -1024; // Time of Flight
30-
short mChargeADC = -1024; // ADC sample
31-
short mFEEBits = 0; //Bit information from FEE
28+
uint8_t mPMNumber = -1; // PhotoMultiplier number (0 to 16)
29+
int16_t mTime = -1024; // Time of Flight
30+
int16_t mChargeADC = -1024; // ADC sample
31+
uint8_t mFEEBits = 0; //Bit information from FEE
3232
enum Flags { Integrator = 0x1 << 0,
3333
DoubleEvent = 0x1 << 1,
3434
Event1TimeLost = 0x1 << 2,
@@ -40,11 +40,11 @@ struct ChannelData {
4040
TimeLost = 0x1 << 8 };
4141

4242
ChannelData() = default;
43-
ChannelData(int channel, float time, short adc, short bits) : mPMNumber(channel), mTime(time), mChargeADC(adc), mFEEBits(bits) {}
43+
ChannelData(uint8_t channel, int time, int adc, uint8_t bits) : mPMNumber(channel), mTime(time), mChargeADC(adc), mFEEBits(bits) {}
4444

4545
void print() const;
4646

47-
ClassDefNV(ChannelData, 2);
47+
ClassDefNV(ChannelData, 3);
4848
};
4949
} // namespace fdd
5050
} // namespace o2

DataFormats/Detectors/FIT/FDD/include/DataFormatsFDD/Digit.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ struct Triggers {
3434
bitCen,
3535
bitSCen };
3636
uint8_t triggersignals = 0; // FDD trigger signals
37-
int8_t nChanA = -1; // number of fired channels A side
38-
int8_t nChanC = -1; // number of fired channels A side
37+
int8_t nChanA = 0; // number of fired channels A side
38+
int8_t nChanC = 0; // number of fired channels A side
3939
int32_t amplA = -1024; // sum amplitude A side
4040
int32_t amplC = -1024; // sum amplitude C side
41-
int16_t timeA = -1024; // average time A side
42-
int16_t timeC = -1024; // average time C side
41+
int16_t timeA = 0; // average time A side
42+
int16_t timeC = 0; // average time C side
4343
Triggers() = default;
4444
Triggers(uint8_t signals, int8_t chanA, int8_t chanC, int32_t aamplA, int32_t aamplC, int16_t atimeA, int16_t atimeC)
4545
{
@@ -51,12 +51,19 @@ struct Triggers {
5151
timeA = atimeA;
5252
timeC = atimeC;
5353
}
54+
55+
bool getOrA() const { return (triggersignals & (1 << bitA)) != 0; }
56+
bool getOrC() const { return (triggersignals & (1 << bitC)) != 0; }
57+
bool getVertex() const { return (triggersignals & (1 << bitVertex)) != 0; }
58+
bool getCen() const { return (triggersignals & (1 << bitCen)) != 0; }
59+
bool getSCen() const { return (triggersignals & (1 << bitSCen)) != 0; }
60+
5461
void cleanTriggers()
5562
{
5663
triggersignals = 0;
57-
nChanA = nChanC = -1;
58-
amplA = amplC = -1024;
59-
timeA = timeC = -1024;
64+
nChanA = nChanC = 0;
65+
amplA = amplC = 0;
66+
timeA = timeC = 0;
6067
}
6168
Triggers getTriggers();
6269

Detectors/FIT/FDD/base/include/FDDBase/Constants.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ constexpr short Ntriggers = 5;
2828
constexpr float IntTimeRes = 0.4;
2929
constexpr float PhotoCathodeEfficiency = 0.18;
3030
constexpr float ChargePerADC = 0.6e-12;
31-
constexpr float PMTransitTime = 6.0; // PM response time (corresponds to 1.9 ns rise time)
32-
constexpr float PMTransparency = 0.25; // Transparency of the first dynode of the PM
33-
constexpr float PMNbOfSecElec = 6.0; // Number of secondary electrons emitted from first dynode (per ph.e.)
31+
constexpr float TimePerTDC = 1. / 0.01302; // time conversion from ns to TDC channels
32+
constexpr float PMTransitTime = 6.0; // PM response time (corresponds to 1.9 ns rise time)
33+
constexpr float PMTransparency = 0.25; // Transparency of the first dynode of the PM
34+
constexpr float PMNbOfSecElec = 6.0; // Number of secondary electrons emitted from first dynode (per ph.e.)
3435

3536
constexpr int NTimeBinsPerBC = 256; // number of samples per BC
3637

Detectors/FIT/FDD/reconstruction/src/ReadRaw.cxx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,24 @@ void ReadRaw::readRawData(const LookUpTable& lut)
8181
for (int i = 0; i < eventHeader.nGBTWords; ++i) {
8282
mRawFileIn.read(reinterpret_cast<char*>(&eventData[2 * i]), o2::fdd::EventData::PayloadSizeFirstWord);
8383
posPayload += o2::fdd::EventData::PayloadSizeFirstWord;
84-
chData = {Short_t(lut.getChannel(link, int(eventData[2 * i].channelID))),
85-
Float_t(eventData[2 * i].time),
86-
Short_t(eventData[2 * i].charge), 0};
84+
chData = {static_cast<uint8_t>(lut.getChannel(link, int(eventData[2 * i].channelID))),
85+
int(eventData[2 * i].time),
86+
int(eventData[2 * i].charge), 0};
8787
mDigitAccum[intrec].emplace_back(chData);
8888
LOG(DEBUG) << " Read 1st half-word: (PMchannel, globalChannel, Q, T, posPayload) = "
8989
<< std::setw(3) << int(eventData[2 * i].channelID)
9090
<< std::setw(4) << lut.getChannel(link, int(eventData[2 * i].channelID))
9191
<< std::setw(5) << int(eventData[2 * i].charge)
92-
<< std::setw(5) << float(eventData[2 * i].time)
92+
<< std::setw(5) << int(eventData[2 * i].time)
9393
<< std::setw(5) << posPayload;
9494

9595
Short_t channelIdFirstHalfWord = chData.mPMNumber;
9696

9797
mRawFileIn.read(reinterpret_cast<char*>(&eventData[2 * i + 1]), EventData::PayloadSizeSecondWord);
9898
posPayload += o2::fdd::EventData::PayloadSizeSecondWord;
99-
chData = {Short_t(lut.getChannel(link, (eventData[2 * i + 1].channelID))),
100-
Float_t(eventData[2 * i + 1].time),
101-
Short_t(eventData[2 * i + 1].charge), 0};
99+
chData = {static_cast<uint8_t>(lut.getChannel(link, int(eventData[2 * i + 1].channelID))),
100+
int(eventData[2 * i + 1].time),
101+
int(eventData[2 * i + 1].charge), 0};
102102
if (chData.mPMNumber <= channelIdFirstHalfWord) {
103103
// Don't save the second half-word if it is only filled with zeroes (empty-data)
104104
// TODO: Verify if it works correctly with real data from readout
@@ -109,7 +109,7 @@ void ReadRaw::readRawData(const LookUpTable& lut)
109109
<< std::setw(3) << int(eventData[2 * i + 1].channelID)
110110
<< std::setw(4) << lut.getChannel(link, int(eventData[2 * i + 1].channelID))
111111
<< std::setw(5) << int(eventData[2 * i + 1].charge)
112-
<< std::setw(5) << float(eventData[2 * i + 1].time)
112+
<< std::setw(5) << int(eventData[2 * i + 1].time)
113113
<< std::setw(5) << posPayload;
114114
}
115115
}
@@ -152,7 +152,7 @@ void ReadRaw::writeDigits(const std::string& outputDigitsFilePath)
152152
size_t nStored = 0;
153153
size_t first = chDataVecTree.size();
154154
for (auto& sec : digit.second) {
155-
chDataVecTree.emplace_back(int(sec.mPMNumber), float(sec.mTime), short(sec.mChargeADC), short(0));
155+
chDataVecTree.emplace_back(sec.mPMNumber, sec.mTime, sec.mChargeADC, sec.mFEEBits);
156156
nStored++;
157157
}
158158
chBcVecTree.emplace_back(first, nStored, digit.first, Triggers());

Detectors/FIT/FDD/simulation/include/FDDSimulation/Digits2Raw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class Digits2Raw
6060
void makeGBTHeader(EventHeader& eventHeader, int link, o2::InteractionRecord const& mIntRecord);
6161
void fillSecondHalfWordAndAddData(int iChannelPerLink, int prevPmLink, const o2::InteractionRecord& ir);
6262
RawEventData mRawEventData;
63+
o2::fdd::Triggers mTriggers;
6364
o2::raw::RawFileWriter mWriter{"FDD"};
6465
bool mOutputPerLink = false;
6566
/////////////////////////////////////////////////

Detectors/FIT/FDD/simulation/src/Digitizer.cxx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void Digitizer::process(const std::vector<o2::fdd::Hit>& hits,
4444
std::sort(sorted_hits.begin(), sorted_hits.end(), [](o2::fdd::Hit const& a, o2::fdd::Hit const& b) {
4545
return a.GetTrackID() < b.GetTrackID();
4646
});
47-
LOG(INFO) << "Pulse";
47+
//LOG(INFO) << "Pulse";
4848
//Conversion of hits to the analogue pulse shape
4949
for (auto& hit : sorted_hits) {
5050
if (hit.GetTime() > 20e3) {
@@ -191,18 +191,24 @@ void Digitizer::storeBC(const BCCache& bc,
191191
{
192192
//LOG(INFO) << "Storing BC " << bc;
193193

194-
int first = digitsCh.size();
194+
int first = digitsCh.size(), nStored = 0;
195195
for (int ic = 0; ic < Nchannels; ic++) {
196-
digitsCh.emplace_back(ic, simulateTimeCFD(bc.pulse[ic]), integrateCharge(bc.pulse[ic]), 0);
196+
float chargeADC = integrateCharge(bc.pulse[ic]);
197+
if (chargeADC != 0) {
198+
digitsCh.emplace_back(ic, int(simulateTimeCFD(bc.pulse[ic])), int(chargeADC), std::rand() % (1 << 8));
199+
nStored++;
200+
}
197201
}
198202
//bc.print();
199203

200-
int nBC = digitsBC.size();
201-
digitsBC.emplace_back(first, 16, bc, mTriggers);
202-
digitsTrig.emplace_back(bc, 0, 0, 0, 0, 0);
204+
if (nStored != 0) {
205+
int nBC = digitsBC.size();
206+
digitsBC.emplace_back(first, nStored, bc, mTriggers);
207+
digitsTrig.emplace_back(bc, 0, 0, 0, 0, 0);
203208

204-
for (const auto& lbl : bc.labels) {
205-
labels.addElement(nBC, lbl);
209+
for (const auto& lbl : bc.labels) {
210+
labels.addElement(nBC, lbl);
211+
}
206212
}
207213
}
208214

@@ -214,7 +220,10 @@ float Digitizer::integrateCharge(const ChannelBCDataF& pulse)
214220
//pulse[iBin] /= ChargePerADC;
215221
chargeADC += pulse[iBin];
216222
}
217-
//saturation if(chargeADC > )chargeADC = ;
223+
//saturation
224+
if (chargeADC > 4095) {
225+
chargeADC = 4095;
226+
}
218227

219228
//LOG(INFO) <<" Charge " << chargeADC;
220229
return std::lround(chargeADC);
@@ -241,7 +250,8 @@ float Digitizer::simulateTimeCFD(const ChannelBCDataF& pulse)
241250
}
242251
}
243252
//LOG(INFO) <<" Time " << timeCFD;
244-
return timeCFD;
253+
timeCFD *= TimePerTDC; //ns -> counts
254+
return std::lround(timeCFD);
245255
}
246256
//_____________________________________________________________________________
247257
o2::fdd::Digitizer::BCCache& Digitizer::setBCCache(const o2::InteractionRecord& ir)

Detectors/FIT/FDD/simulation/src/Digits2Raw.cxx

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,23 @@ void Digits2Raw::convertDigits(o2::fdd::Digit bcdigits, gsl::span<const ChannelD
101101
iChannelPerLink = 0;
102102
prevPmLink = nLinkPm;
103103
}
104-
if (pmchannels[ich].mChargeADC != 0) {
105-
LOG(DEBUG) << " Store data for channel: " << ich << " PmLink = " << nLinkPm << " ";
106-
auto& newData = mRawEventData.mEventData[iChannelPerLink];
107-
newData.charge = pmchannels[ich].mChargeADC;
108-
newData.time = pmchannels[ich].mTime;
109-
newData.generateFlags();
110-
newData.channelID = lut.getModChannel(pmchannels[ich].mPMNumber);
111-
iChannelPerLink++;
112-
}
104+
LOG(DEBUG) << " Store data for channel: " << ich << " PmLink = " << nLinkPm << " ";
105+
auto& newData = mRawEventData.mEventData[iChannelPerLink];
106+
newData.charge = pmchannels[ich].mChargeADC;
107+
newData.time = pmchannels[ich].mTime;
108+
109+
newData.numberADC = bool(pmchannels[ich].mFEEBits & ChannelData::Integrator);
110+
newData.isDoubleEvent = bool(pmchannels[ich].mFEEBits & ChannelData::DoubleEvent);
111+
newData.is1TimeLostEvent = bool(pmchannels[ich].mFEEBits & ChannelData::Event1TimeLost);
112+
newData.is2TimeLostEvent = bool(pmchannels[ich].mFEEBits & ChannelData::Event2TimeLost);
113+
newData.isADCinGate = bool(pmchannels[ich].mFEEBits & ChannelData::AdcInGate);
114+
newData.isTimeInfoLate = bool(pmchannels[ich].mFEEBits & ChannelData::TimeTooLate);
115+
newData.isAmpHigh = bool(pmchannels[ich].mFEEBits & ChannelData::AmpTooHigh);
116+
newData.isEventInTVDC = bool(pmchannels[ich].mFEEBits & ChannelData::EventInTrigger);
117+
newData.isTimeInfoLost = bool(pmchannels[ich].mFEEBits & ChannelData::TimeLost);
118+
119+
newData.channelID = lut.getModChannel(pmchannels[ich].mPMNumber);
120+
iChannelPerLink++;
113121
if (ich == nch - 1) {
114122
fillSecondHalfWordAndAddData(iChannelPerLink, prevPmLink, intRecord);
115123
}
@@ -119,17 +127,41 @@ void Digits2Raw::convertDigits(o2::fdd::Digit bcdigits, gsl::span<const ChannelD
119127
makeGBTHeader(mRawEventData.mEventHeader, sTcmLink, intRecord);
120128
mRawEventData.mEventHeader.nGBTWords = 1;
121129
auto& tcmdata = mRawEventData.mTCMdata;
122-
tcmdata.vertex = 1;
123-
tcmdata.orA = 1;
124-
tcmdata.orC = 0;
125-
tcmdata.sCen = 0;
126-
tcmdata.cen = 0;
127-
tcmdata.nChanA = 0;
128-
tcmdata.nChanC = 0;
129-
tcmdata.amplA = 0;
130-
tcmdata.amplC = 0;
131-
tcmdata.timeA = 0;
132-
tcmdata.timeC = 0;
130+
mTriggers = bcdigits.mTriggers;
131+
132+
float ampA = mTriggers.amplA;
133+
float ampC = mTriggers.amplC;
134+
if (ampA > 131071) {
135+
ampA = 131071; //2^17
136+
}
137+
if (ampC > 131071) {
138+
ampC = 131071; //2^17
139+
}
140+
tcmdata.vertex = mTriggers.getVertex();
141+
tcmdata.orA = mTriggers.getOrA();
142+
tcmdata.orC = mTriggers.getOrC();
143+
tcmdata.sCen = mTriggers.getSCen();
144+
tcmdata.cen = mTriggers.getCen();
145+
tcmdata.nChanA = mTriggers.nChanA;
146+
tcmdata.nChanC = mTriggers.nChanC;
147+
tcmdata.amplA = ampA;
148+
tcmdata.amplC = ampC;
149+
tcmdata.timeA = mTriggers.timeA;
150+
tcmdata.timeC = mTriggers.timeC;
151+
LOG(DEBUG) << " TCM triggers read "
152+
<< " time A " << mTriggers.timeA << " time C " << mTriggers.timeC
153+
<< " amp A " << ampA << " amp C " << ampC
154+
<< " N A " << int(mTriggers.nChanA) << " N C " << int(mTriggers.nChanC)
155+
<< " trig "
156+
<< " ver " << mTriggers.getVertex() << " A " << mTriggers.getOrA() << " C " << mTriggers.getOrC();
157+
158+
LOG(DEBUG) << "TCMdata"
159+
<< " time A " << tcmdata.timeA << " time C " << tcmdata.timeC
160+
<< " amp A " << tcmdata.amplA << " amp C " << tcmdata.amplC
161+
<< " N A " << int(tcmdata.nChanA) << " N C " << int(tcmdata.nChanC)
162+
<< " trig "
163+
<< " ver " << tcmdata.vertex << " A " << tcmdata.orA << " C " << tcmdata.orC
164+
<< " size " << sizeof(tcmdata);
133165

134166
auto data = mRawEventData.to_vector(kTRUE); //for tcm module
135167
uint32_t linkId = uint32_t(sTcmLink);

Detectors/FIT/FDD/workflow/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
o2_add_library(FDDWorkflow
1212
SOURCES src/DigitReaderSpec.cxx
13-
src/DigitWriterSpec.cxx
1413
src/EntropyEncoderSpec.cxx
1514
src/EntropyDecoderSpec.cxx
1615
src/RecoWorkflow.cxx

Detectors/FIT/FDD/workflow/include/FDDWorkflow/DigitReaderSpec.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ class DigitReader : public Task
3737
void run(ProcessingContext& pc) final;
3838

3939
private:
40-
bool mUseMC = true; // use MC truth
40+
bool mTrigInp = true; // read trigger inputs
41+
bool mUseMC = true; // use MC truth
4142
o2::header::DataOrigin mOrigin = o2::header::gDataOriginFDD;
4243

4344
std::string mInputFileName = "";
4445
std::string mDigitTreeName = "o2sim";
4546
std::string mDigitBCBranchName = "FDDDigit";
4647
std::string mDigitChBranchName = "FDDDigitCh";
48+
std::string mTriggerBranchName = "TRIGGERINPUT";
4749
std::string mDigitMCTruthBranchName = "FDDDigitLabels";
4850
};
4951

0 commit comments

Comments
 (0)