Skip to content

Commit 97a416c

Browse files
committed
Optionally apply BC shift to triggered detectors in CTF decoding
The TriggerOffsetsParam configurableParam got array of custom corrections per detector (0 by default) which can be applied to triggered detectors IR as an ADDITIVE correction during CTF decoding. Note that this convention is opposite to that for the LM_L0 convention which is subtracted from the encoded IR (at the moment only for the TRD if an option --correct-trd-trigger-offset was provided to the ctf-reader). Therefore, for the TRD, if this option is ON, the effect of the correction is ir_corrected = ir_decoded - TriggerOffsetsParam::LM_L0 + TriggerOffsetsParam::customOffset[TRD]; while for other EMC,PHS,CPV and HMP (and TRD in absence of --correct-trd-trigger-offset) it is simply ir_corrected = ir_decoded + TriggerOffsetsParam::customOffset[<det>]; In case the correction moves the IR before the TF 1st orbit, the trigger is discarded. Extra: ZDC in pbpb2022 was reseting the orbit internally to 1 at the SOR: implemented the shift also for it.
1 parent e5a71fd commit 97a416c

25 files changed

Lines changed: 126 additions & 29 deletions

File tree

DataFormats/Detectors/CTP/include/DataFormatsCTP/TriggerOffsetsParam.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ namespace o2
2222
namespace ctp
2323
{
2424
struct TriggerOffsetsParam : public o2::conf::ConfigurableParamHelper<TriggerOffsetsParam> {
25+
static constexpr int MaxNDet = 32; // take with margin to account for possible changes / upgrades
2526
int64_t LM_L0 = 15;
2627
int64_t L0_L1 = 280;
27-
28+
int64_t customOffset[MaxNDet] = {};
2829
O2ParamDef(TriggerOffsetsParam, "TriggerOffsetsParam"); // boilerplate stuff + make principal key
2930
};
3031
} // namespace ctp

Detectors/Base/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ o2_add_library(DetectorsBase
2828
PUBLIC_LINK_LIBRARIES FairRoot::Base
2929
O2::CommonUtils
3030
O2::DetectorsCommonDataFormats
31+
O2::DataFormatsCTP
3132
O2::GPUCommon
3233
O2::GPUUtils
3334
O2::ReconstructionDataFormats

Detectors/Base/include/DetectorsBase/CTFCoderBase.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "DetectorsCommonDataFormats/CTFDictHeader.h"
2626
#include "DetectorsCommonDataFormats/CTFHeader.h"
2727
#include "DetectorsCommonDataFormats/CTFIOSize.h"
28+
#include "DataFormatsCTP/TriggerOffsetsParam.h"
2829
#include "rANS/rans.h"
2930
#include <filesystem>
3031
#include "Framework/InitContext.h"
@@ -125,10 +126,22 @@ class CTFCoderBase
125126
size_t getIRFrameSelMarginBwd() const { return mIRFrameSelMarginBwd; }
126127
size_t getIRFrameSelMarginFwd() const { return mIRFrameSelMarginFwd; }
127128

129+
void setBCShift(int64_t n) { mBCShift = n; }
130+
void setFirstTFOrbit(uint32_t n) { mFirstTFOrbit = n; }
131+
auto getBCShist() const { return mBCShift; }
132+
auto getFirstTFOrbit() const { return mFirstTFOrbit; }
133+
void setSupportBCShifts(bool v = true) { mSupportBCShifts = v; }
134+
bool getSupportBCShifts() const { return mSupportBCShifts; }
135+
128136
protected:
129137
std::string getPrefix() const { return o2::utils::Str::concat_string(mDet.getName(), "_CTF: "); }
130138
void checkDictVersion(const CTFDictHeader& h) const;
131139
bool isTreeDictionary(const void* buff) const;
140+
bool canApplyBCShift(const o2::InteractionRecord& ir) const
141+
{
142+
auto diff = ir.differenceInBC({0, mFirstTFOrbit});
143+
return diff < 0 ? true : diff >= mBCShift;
144+
}
132145
template <typename CTF>
133146
std::vector<char> loadDictionaryFromTree(TTree* tree);
134147
std::vector<std::shared_ptr<void>> mCoders; // encoders/decoders
@@ -137,7 +150,10 @@ class CTFCoderBase
137150
o2::utils::IRFrameSelector mIRFrameSelector; // optional IR frames selector
138151
float mMemMarginFactor = 1.0f; // factor for memory allocation in EncodedBlocks
139152
bool mLoadDictFromCCDB{true};
153+
bool mSupportBCShifts{false};
140154
OpType mOpType; // Encoder or Decoder
155+
int64_t mBCShift = 0; // shift to apply to decoded IR (i.e. CTP offset if was not corrected on raw data decoding level)
156+
uint32_t mFirstTFOrbit = 0;
141157
size_t mIRFrameSelMarginBwd = 0; // margin in BC to add to the IRFrame lower boundary when selection is requested
142158
size_t mIRFrameSelMarginFwd = 0; // margin in BC to add to the IRFrame upper boundary when selection is requested
143159
int mVerbosity = 0;
@@ -293,6 +309,17 @@ bool CTFCoderBase::finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, voi
293309
LOGP(info, "Loaded {} from CCDB", mExtHeader.asString());
294310
}
295311
mLoadDictFromCCDB = false; // we read the dictionary at most once!
312+
} else if ((match = (matcher == o2::framework::ConcreteDataMatcher("CTP", "Trig_Offset", 0)))) {
313+
const auto& trigOffsParam = o2::ctp::TriggerOffsetsParam::Instance();
314+
auto bcshift = trigOffsParam.customOffset[mDet.getID()];
315+
if (bcshift) {
316+
if (mSupportBCShifts) {
317+
LOGP(info, "Decoded IRs will be augmented by {} BCs, discarded if become prior to 1st orbit", bcshift);
318+
setBCShift(-bcshift); // offset is subtracted
319+
} else {
320+
LOGP(alarm, "Decoding with {} BCs shift is requested, but the {} does not support this operation, ignoring request", bcshift, mDet.getName());
321+
}
322+
}
296323
}
297324
return match;
298325
}

Detectors/Base/src/CTFCoderBase.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "Framework/ControlService.h"
1818
#include "Framework/ProcessingContext.h"
1919
#include "Framework/InputRecord.h"
20+
#include "Framework/TimingInfo.h"
2021

2122
using namespace o2::ctf;
2223
using namespace o2::framework;
@@ -47,6 +48,10 @@ void CTFCoderBase::assignDictVersion(CTFDictHeader& h) const
4748

4849
void CTFCoderBase::updateTimeDependentParams(ProcessingContext& pc, bool askTree)
4950
{
51+
setFirstTFOrbit(pc.services().get<o2::framework::TimingInfo>().firstTForbit);
52+
if (mOpType == OpType::Decoder) {
53+
pc.inputs().get<o2::ctp::TriggerOffsetsParam*>("trigoffset"); // this is a configurable param
54+
}
5055
if (mLoadDictFromCCDB) {
5156
if (askTree) {
5257
pc.inputs().get<TTree*>("ctfdict"); // just to trigger the finaliseCCDB

Detectors/CPV/reconstruction/include/CPVReconstruction/CTFCoder.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ o2::ctf::CTFIOSize CTFCoder::decode(const CTF::base& ec, VTRG& trigVec, VCLUSTER
157157

158158
uint32_t firstEntry = 0, cluCount = 0;
159159
o2::InteractionRecord ir(header.firstBC, header.firstOrbit);
160-
160+
bool checkIROK = (mBCShift == 0); // need to check if CTP offset correction does not make the local time negative ?
161161
Cluster clu;
162162
for (uint32_t itrig = 0; itrig < header.nTriggers; itrig++) {
163163
// restore TrigRecord
@@ -167,14 +167,19 @@ o2::ctf::CTFIOSize CTFCoder::decode(const CTF::base& ec, VTRG& trigVec, VCLUSTER
167167
} else {
168168
ir.bc += bcInc[itrig];
169169
}
170-
170+
if (checkIROK || canApplyBCShift(ir)) { // correction will be ok
171+
checkIROK = true;
172+
} else { // correction would make IR prior to mFirstTFOrbit, skip
173+
cluCount += entries[itrig];
174+
continue;
175+
}
171176
firstEntry = cluVec.size();
172177
for (uint16_t ic = 0; ic < entries[itrig]; ic++) {
173178
clu.setPacked(posX[cluCount], posZ[cluCount], energy[cluCount], status[cluCount]);
174179
cluVec.emplace_back(clu);
175180
cluCount++;
176181
}
177-
trigVec.emplace_back(ir, firstEntry, entries[itrig]);
182+
trigVec.emplace_back(ir - mBCShift, firstEntry, entries[itrig]);
178183
}
179184
assert(cluCount == header.nClusters);
180185
iosize.rawIn = trigVec.size() * sizeof(TriggerRecord) + cluVec.size() * sizeof(Cluster);

Detectors/CPV/workflow/src/EntropyDecoderSpec.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ EntropyDecoderSpec::EntropyDecoderSpec(int verbosity) : mCTFCoder(o2::ctf::CTFCo
3030
mTimer.Stop();
3131
mTimer.Reset();
3232
mCTFCoder.setVerbosity(verbosity);
33+
mCTFCoder.setSupportBCShifts(true);
3334
}
3435

3536
void EntropyDecoderSpec::finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj)
@@ -82,6 +83,7 @@ DataProcessorSpec getEntropyDecoderSpec(int verbosity, unsigned int sspec)
8283
std::vector<InputSpec> inputs;
8384
inputs.emplace_back("ctf", "CPV", "CTFDATA", sspec, Lifetime::Timeframe);
8485
inputs.emplace_back("ctfdict", "CPV", "CTFDICT", 0, Lifetime::Condition, ccdbParamSpec("CPV/Calib/CTFDictionary"));
86+
inputs.emplace_back("trigoffset", "CTP", "Trig_Offset", 0, Lifetime::Condition, ccdbParamSpec("CTP/Config/TriggerOffsets"));
8587

8688
return DataProcessorSpec{
8789
"cpv-entropy-decoder",

Detectors/CTP/workflow/src/EntropyDecoderSpec.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ EntropyDecoderSpec::EntropyDecoderSpec(int verbosity) : mCTFCoder(o2::ctf::CTFCo
2929
{
3030
mTimer.Stop();
3131
mTimer.Reset();
32+
mCTFCoder.setVerbosity(verbosity);
3233
}
3334

3435
void EntropyDecoderSpec::finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj)
@@ -81,6 +82,7 @@ DataProcessorSpec getEntropyDecoderSpec(int verbosity, unsigned int sspec)
8182
std::vector<InputSpec> inputs;
8283
inputs.emplace_back("ctf", "CTP", "CTFDATA", sspec, Lifetime::Timeframe);
8384
inputs.emplace_back("ctfdict", "CTP", "CTFDICT", 0, Lifetime::Condition, ccdbParamSpec("CTP/Calib/CTFDictionaryTree"));
85+
inputs.emplace_back("trigoffset", "CTP", "Trig_Offset", 0, Lifetime::Condition, ccdbParamSpec("CTP/Config/TriggerOffsets"));
8486

8587
return DataProcessorSpec{
8688
"ctp-entropy-decoder",

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ o2::ctf::CTFIOSize CTFCoder::decode(const CTF::base& ec, VTRG& trigVec, VCELL& c
168168

169169
uint32_t firstEntry = 0, cellCount = 0;
170170
o2::InteractionRecord ir(header.firstBC, header.firstOrbit);
171-
171+
bool checkIROK = (mBCShift == 0); // need to check if CTP offset correction does not make the local time negative ?
172172
Cell cell;
173173
TriggerRecord trg;
174174
for (uint32_t itrig = 0; itrig < header.nTriggers; itrig++) {
@@ -179,14 +179,20 @@ o2::ctf::CTFIOSize CTFCoder::decode(const CTF::base& ec, VTRG& trigVec, VCELL& c
179179
} else {
180180
ir.bc += bcInc[itrig];
181181
}
182-
182+
if (checkIROK || canApplyBCShift(ir)) { // correction will be ok
183+
checkIROK = true;
184+
} else { // correction would make IR prior to mFirstTFOrbit, skip
185+
cellCount += entries[itrig];
186+
continue;
187+
}
183188
firstEntry = cellVec.size();
189+
184190
for (uint16_t ic = 0; ic < entries[itrig]; ic++) {
185191
cell.setPacked(tower[cellCount], cellTime[cellCount], energy[cellCount], status[cellCount]);
186192
cellVec.emplace_back(cell);
187193
cellCount++;
188194
}
189-
trg.setBCData(ir);
195+
trg.setBCData(ir - mBCShift);
190196
trg.setDataRange(firstEntry, entries[itrig]);
191197
trg.setTriggerBitsCompressed(trigger[itrig]);
192198
trigVec.emplace_back(trg);

Detectors/EMCAL/workflow/src/EntropyDecoderSpec.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ EntropyDecoderSpec::EntropyDecoderSpec(int verbosity, unsigned int sspecOut) : m
3030
mTimer.Stop();
3131
mTimer.Reset();
3232
mCTFCoder.setVerbosity(verbosity);
33+
mCTFCoder.setSupportBCShifts(true);
3334
}
3435

3536
void EntropyDecoderSpec::finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj)
@@ -82,6 +83,7 @@ DataProcessorSpec getEntropyDecoderSpec(int verbosity, unsigned int sspecInp, un
8283
std::vector<InputSpec> inputs;
8384
inputs.emplace_back("ctf", "EMC", "CTFDATA", sspecInp, Lifetime::Timeframe);
8485
inputs.emplace_back("ctfdict", "EMC", "CTFDICT", 0, Lifetime::Condition, ccdbParamSpec("EMC/Calib/CTFDictionary"));
86+
inputs.emplace_back("trigoffset", "CTP", "Trig_Offset", 0, Lifetime::Condition, ccdbParamSpec("CTP/Config/TriggerOffsets"));
8587

8688
return DataProcessorSpec{
8789
"emcal-entropy-decoder",

Detectors/FIT/FDD/workflow/src/EntropyDecoderSpec.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ DataProcessorSpec getEntropyDecoderSpec(int verbosity, unsigned int sspec)
8282
std::vector<InputSpec> inputs;
8383
inputs.emplace_back("ctf", "FDD", "CTFDATA", sspec, Lifetime::Timeframe);
8484
inputs.emplace_back("ctfdict", "FDD", "CTFDICT", 0, Lifetime::Condition, ccdbParamSpec("FDD/Calib/CTFDictionary"));
85+
inputs.emplace_back("trigoffset", "CTP", "Trig_Offset", 0, Lifetime::Condition, ccdbParamSpec("CTP/Config/TriggerOffsets"));
8586

8687
return DataProcessorSpec{
8788
"fdd-entropy-decoder",

0 commit comments

Comments
 (0)