diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackAlgoBaseR.h b/reco/detectors/trd/unpack/CbmTrdUnpackAlgoBaseR.h index 07ccdd80edb98c25a75a3fc16b7698cff2d2832a..420d2a7d3c20d8767b834ee1d849f72f923f6b52 100644 --- a/reco/detectors/trd/unpack/CbmTrdUnpackAlgoBaseR.h +++ b/reco/detectors/trd/unpack/CbmTrdUnpackAlgoBaseR.h @@ -74,6 +74,23 @@ public: */ void SetSpadicObject(std::shared_ptr<CbmTrdSpadic> value) { fSpadic = value; } + /** + * @brief Register a time offeset to be substracted from the digis which come from a specific CRI + * + * @param map + */ + void SetElinkTimeOffsetMap(std::map<std::uint32_t, std::vector<std::int32_t>> map) { fElinkTimeOffsetMap = map; } + + /** + * @brief Get the time offeset to be substracted from the digis which come from a specific CRI + * + * @param criid + */ + std::int32_t GetElinkTimeOffset(std::uint32_t criid, std::uint8_t elinkid) + { + return (fElinkTimeOffsetMap.find(criid) == fElinkTimeOffsetMap.end() ? 0 : fElinkTimeOffsetMap[criid].at(elinkid)); + } + protected: /** * @brief Handle the output created by the explicit algorithms. E.g. write to output vectors. @@ -207,7 +224,10 @@ protected: /** @brief length of one ts_msb in [cc] */ size_t fTsMsbLengthCC = fTsMsbLength / CbmTrdSpadic::GetClockCycle(); -private: + /** @brief Map to store time offsets for each CRI&Elink combination */ + std::map<std::uint32_t, std::vector<std::int32_t>> fElinkTimeOffsetMap; + + private: ClassDef(CbmTrdUnpackAlgoBaseR, 2) }; diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.cxx b/reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.cxx index 98da832c11ae064005e5af5b69b3f5f52ab38cfe..1860d6fbbc1d32bacace368cf04910725d8f67f8 100644 --- a/reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.cxx +++ b/reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.cxx @@ -306,6 +306,7 @@ void CbmTrdUnpackAlgoR::makeDigi(CbmTrdRawMessageSpadic raw) ULong64_t time = raw.GetTime(); time -= fSystemTimeOffset; + time -= GetElinkTimeOffset(raw.GetCriId(), raw.GetElinkId()); auto digi = fRTDMethod->MakeDigi(raw.GetSamples(), padChNr, uniqueModuleId, time, triggerType, errClass); @@ -338,6 +339,7 @@ void CbmTrdUnpackAlgoR::makeDigi(Spadic::FexWord<0x10> fw, std::uint32_t criid) auto energy = fSpadic->MaxAdcToEnergyCal(fw.maxAdc); time -= fSystemTimeOffset; + time -= GetElinkTimeOffset(criid, fw.elink); auto digi = std::unique_ptr<CbmTrdDigi>(new CbmTrdDigi(padChNr, uniqueModuleId, energy, time, triggerType, 0)); diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackConfig.cxx b/reco/detectors/trd/unpack/CbmTrdUnpackConfig.cxx index 51466ca551c26c8e7bb3afbe2cdb058cc23a1f53..6bd5659913b8e5aecf8708acaf4839b2a80fa100 100644 --- a/reco/detectors/trd/unpack/CbmTrdUnpackConfig.cxx +++ b/reco/detectors/trd/unpack/CbmTrdUnpackConfig.cxx @@ -46,6 +46,10 @@ void CbmTrdUnpackConfig::SetAlgo() if (fDoLog) LOG(info) << fName << "::SetAlgo - SetSystemTimeOffset"; algo->SetSystemTimeOffset(fSystemTimeOffset); + // Set the global system time offset + if (fDoLog) LOG(info) << fName << "::SetAlgo - SetElinkTimeOffsetMap"; + algo->SetElinkTimeOffsetMap(fElinkTimeOffsetMap); + // If we have a monitor in the config add it to the algo if (fMonitor) algo->SetMonitor(fMonitor); @@ -87,5 +91,16 @@ std::shared_ptr<CbmTrdUnpackAlgoBaseR> CbmTrdUnpackConfig::chooseAlgo() return nullptr; } +void CbmTrdUnpackConfig::SetElinkTimeOffset(std::uint32_t criid, std::uint8_t elinkid, std::int32_t offsetNs) +{ + // create vector for criid if not yet existing + if (fElinkTimeOffsetMap.find(criid) == fElinkTimeOffsetMap.end()) { + //vector has fixed size of 256 (max elinkid) and is initialized to 0 + fElinkTimeOffsetMap.insert(std::make_pair(criid, std::vector<int32_t>(256, 0))); + } + + fElinkTimeOffsetMap[criid][elinkid] = offsetNs; +} + ClassImp(CbmTrdUnpackConfig) diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackConfig.h b/reco/detectors/trd/unpack/CbmTrdUnpackConfig.h index 0d81b49c3f5adea464f577f81f31b756476d88fa..ad3d82ff3d5ff3d31646e170826058729299c5cc 100644 --- a/reco/detectors/trd/unpack/CbmTrdUnpackConfig.h +++ b/reco/detectors/trd/unpack/CbmTrdUnpackConfig.h @@ -91,7 +91,16 @@ public: */ void SetSpadicObject(std::shared_ptr<CbmTrdSpadic> value) { fSpadic = value; } -protected: + /** + * @brief Register a time offeset to be substracted from the digis which come from a specific CRI + * + * @param criid + * @param elinkid + * @param offsetNs + */ + void SetElinkTimeOffset(std::uint32_t criid, std::uint8_t elinkid, std::int32_t offsetNs); + + protected: /** * @brief Choose the derived unpacker algorithm to be used for the DAQ output to Digi translation. If algo was already set manually by the user this algorithm is used. * @@ -108,7 +117,10 @@ protected: /** @brief pointer to the monitor object */ std::shared_ptr<CbmTrdUnpackMonitor> fMonitor = nullptr; -private: + /** @brief Map to store time offsets for each CRI&Elink combination */ + std::map<std::uint32_t, std::vector<std::int32_t>> fElinkTimeOffsetMap; + + private: ClassDef(CbmTrdUnpackConfig, 3) };