42ClustererDPL<N>::ClustererDPL(std::shared_ptr<o2::base::GRPGeomRequest> gr,
bool useMC,
bool doStag) : mGGCCDBRequest(gr), mUseMC(useMC), mDoStaggering(doStag)
52 mClusterer = std::make_unique<o2::itsmft::Clusterer>();
54 mUseClusterDictionary = !ic.
options().
get<
bool>(
"ignore-cluster-dictionary");
56 mNThreads = std::max(1, ic.
options().
get<
int>(
"nthreads"));
57 mDetName =
Origin.as<std::string>();
60 for (
int iLayer = 0; iLayer < mLayers; ++iLayer) {
61 mFilter.emplace_back(
"digits",
Origin,
"DIGITS", iLayer, Lifetime::Timeframe);
62 mFilter.emplace_back(
"ROframe",
Origin,
"DIGITSROF", iLayer, Lifetime::Timeframe);
64 mFilter.emplace_back(
"labels",
Origin,
"DIGITSMCTR", iLayer, Lifetime::Timeframe);
72 updateTimeDependentParams(pc);
75 std::vector<gsl::span<const o2::itsmft::Digit>>
digits(mLayers);
76 std::vector<gsl::span<const o2::itsmft::ROFRecord>> rofs(mLayers);
77 std::vector<gsl::span<const char>> labelsbuffer(mLayers);
79 auto const* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(
ref);
84 rofs[dh->subSpecification] = pc.
inputs().
get<gsl::span<o2::itsmft::ROFRecord>>(
ref);
87 labelsbuffer[dh->subSpecification] = pc.
inputs().
get<gsl::span<char>>(
ref);
100 for (
uint32_t iLayer{0}; iLayer < mLayers; ++iLayer) {
101 int layer = (mDoStaggering) ? iLayer : -1;
103 LOG(info) << mDetName <<
"Clusterer" << ((mDoStaggering) ? std::format(
" on layer {}",
layer) :
"") <<
" pulled " <<
digits[iLayer].
size() <<
" digits, in " << rofs[iLayer].size() <<
" RO frames";
105 mClusterer->setMaxROFDepthToSquash(mClusterer->getMaxROFDepthToSquash(
layer));
113 LOG(info) << mDetName <<
"Clusterer" << ((mDoStaggering) ? std::format(
" on layer {}",
layer) :
"") <<
" pulled " <<
labels.getNElements() <<
" labels ";
117 std::vector<o2::itsmft::CompClusterExt> clusCompVec;
118 std::vector<o2::itsmft::ROFRecord> clusROFVec;
119 std::vector<unsigned char> clusPattVec;
121 std::unique_ptr<o2::dataformats::MCTruthContainer<o2::MCCompLabel>> clusterLabels;
123 clusterLabels = std::make_unique<o2::dataformats::MCTruthContainer<o2::MCCompLabel>>();
125 mClusterer->process(mNThreads, reader, &clusCompVec, &clusPattVec, &clusROFVec, clusterLabels.get());
128 size_t nROFs = clusROFVec.size();
129 const int nROFsPerOrbit = o2::constants::lhc::LHCMaxBunches / par.getROFLengthInBC(iLayer);
133 std::vector<o2::itsmft::ROFRecord> expClusRofVec(nROFsTF);
134 for (
int iROF{0}; iROF < nROFsTF; ++iROF) {
135 auto& rof = expClusRofVec[iROF];
136 int orb = iROF * par.getROFLengthInBC(iLayer) / o2::constants::lhc::LHCMaxBunches + firstTForbit;
137 int bc = iROF * par.getROFLengthInBC(iLayer) % o2::constants::lhc::LHCMaxBunches + par.getROFDelayInBC(iLayer);
140 rof.setROFrame(iROF);
142 rof.setFirstEntry(-1);
145 for (
const auto& rof : clusROFVec) {
146 const auto&
ir = rof.getBCData();
148 LOGP(warn,
"Discard ROF {} preceding TF 1st orbit {}{}",
ir.
asString(), firstTForbit, ((mDoStaggering) ? std::format(
" on layer {}",
layer) :
""));
151 auto irToFirst =
ir - firstIR;
152 if (irToFirst.toLong() - par.getROFDelayInBC(iLayer) < 0) {
153 LOGP(warn,
"Discard ROF {} preceding TF 1st orbit {} due to imposed ROF delay{}",
ir.
asString(), firstTForbit, ((mDoStaggering) ? std::format(
" on layer {}", iLayer) :
""));
156 irToFirst -= par.getROFDelayInBC(iLayer);
157 const long irROF = irToFirst.toLong() / par.getROFLengthInBC(iLayer);
158 if (irROF >= nROFsTF) {
159 LOGP(warn,
"Discard ROF {} exceeding TF orbit range{}",
ir.
asString(), ((mDoStaggering) ? std::format(
" on layer {}",
layer) :
""));
162 auto& expROF = expClusRofVec[irROF];
163 if (expROF.getNEntries() == 0) {
164 expROF.setFirstEntry(rof.getFirstEntry());
165 expROF.setNEntries(rof.getNEntries());
167 if (expROF.getNEntries() < rof.getNEntries()) {
168 LOGP(warn,
"Repeating {} with {} clusters, prefer to already processed instance with {} clusters{}", rof.asString(), rof.getNEntries(), expROF.getNEntries(), ((mDoStaggering) ? std::format(
" on layer {}",
layer) :
""));
169 expROF.setFirstEntry(rof.getFirstEntry());
170 expROF.setNEntries(rof.getNEntries());
172 LOGP(warn,
"Repeating {} with {} clusters, discard preferring already processed instance with {} clusters{}", rof.asString(), rof.getNEntries(), expROF.getNEntries(), ((mDoStaggering) ? std::format(
" on layer {}",
layer) :
""));
177 for (
auto& rof : expClusRofVec) {
178 if (rof.getFirstEntry() < 0) {
179 rof.setFirstEntry(prevLast);
181 prevLast = rof.getFirstEntry() + rof.getNEntries();
183 nROFs = expClusRofVec.size();
194 static std::vector<o2::itsmft::MC2ROFRecord> dummyMC2ROF;
200 LOG(info) << mDetName <<
"Clusterer" << ((mDoStaggering) ? std::format(
": {}", iLayer) :
"") <<
" pushed " << clusCompVec.size() <<
" clusters, in " << nROFs <<
" RO frames in " <<
sw.RealTime() <<
" s";
203 LOG(info) << mDetName <<
"Clusterer produced " <<
nClusters <<
" clusters";
211 static bool initOnceDone =
false;
221 if (clParams.maxBCDiffToMaskBias > 0 && clParams.maxBCDiffToSquashBias > 0) {
222 LOGP(fatal,
"maxBCDiffToMaskBias = {} and maxBCDiffToSquashBias = {} cannot be set at the same time. Either set masking or squashing with a BCDiff > 0", clParams.maxBCDiffToMaskBias, clParams.maxBCDiffToSquashBias);
224 mClusterer->setDropHugeClusters(clParams.dropHugeClusters);
225 auto nbc = clParams.maxBCDiffToMaskBias;
226 nbc += mClusterer->isContinuousReadOut() ? alpParams.roFrameLengthInBC : (alpParams.roFrameLengthTrig / o2::constants::lhc::LHCBunchSpacingNS);
227 mClusterer->setMaxBCSeparationToMask(nbc);
228 mClusterer->setMaxRowColDiffToMask(clParams.maxRowColDiffToMask);
230 int rofBC = mClusterer->isContinuousReadOut() ? alpParams.roFrameLengthInBC : (alpParams.roFrameLengthTrig / o2::constants::lhc::LHCBunchSpacingNS);
231 mClusterer->setMaxBCSeparationToSquash(rofBC + clParams.maxBCDiffToSquashBias);
232 int nROFsToSquash = 0;
233 if (clParams.maxSOTMUS > 0 && rofBC > 0) {
234 nROFsToSquash = 2 + int(clParams.maxSOTMUS / (rofBC * o2::constants::lhc::LHCBunchSpacingMUS));
236 mClusterer->setMaxROFDepthToSquash(nROFsToSquash);
238 if (mClusterer->isContinuousReadOut()) {
239 for (
int iLayer{0}; iLayer < mLayers; ++iLayer) {
240 mClusterer->addMaxBCSeparationToSquash(alpParams.getROFLengthInBC(iLayer) + clParams.getMaxBCDiffToSquashBias(iLayer));
241 mClusterer->addMaxROFDepthToSquash((clParams.getMaxBCDiffToSquashBias(iLayer) > 0) ? 2 +
int(clParams.maxSOTMUS / (alpParams.getROFLengthInBC(iLayer) * o2::constants::lhc::LHCBunchSpacingMUS)) : 0);
245 mClusterer->print(
false);
258 LOG(info) <<
"cluster dictionary updated" << (!mUseClusterDictionary ?
" but its using is disabled" :
"");
259 if (mUseClusterDictionary) {
266 LOG(info) <<
"Alpide param updated";
268 par.printKeyValues();
272 LOG(info) <<
"Cluster param updated";
274 par.printKeyValues();
285 std::vector<InputSpec> inputs;
287 for (uint32_t iLayer = 0; iLayer < nLayers; ++iLayer) {
288 inputs.emplace_back(
"digits", Origin,
"DIGITS", iLayer, Lifetime::Timeframe);
289 inputs.emplace_back(
"ROframes", Origin,
"DIGITSROF", iLayer, Lifetime::Timeframe);
291 inputs.emplace_back(
"labels", Origin,
"DIGITSMCTR", iLayer, Lifetime::Timeframe);
294 inputs.emplace_back(
"cldict", Origin,
"CLUSDICT", 0, Lifetime::Condition,
ccdbParamSpec(
Origin.as<std::string>() +
"/Calib/ClusterDictionary"));
295 inputs.emplace_back(
"cluspar", Origin,
"CLUSPARAM", 0, Lifetime::Condition,
ccdbParamSpec(
Origin.as<std::string>() +
"/Config/ClustererParam"));
296 inputs.emplace_back(
"alppar", Origin,
"ALPIDEPARAM", 0, Lifetime::Condition,
ccdbParamSpec(
Origin.as<std::string>() +
"/Config/AlpideParam"));
297 auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(
false,
305 std::vector<OutputSpec> outputs;
307 outputs.emplace_back(Origin,
"COMPCLUSTERS", iLayer, Lifetime::Timeframe);
308 outputs.emplace_back(Origin,
"PATTERNS", iLayer, Lifetime::Timeframe);
309 outputs.emplace_back(Origin,
"CLUSTERSROF", iLayer, Lifetime::Timeframe);
311 outputs.emplace_back(Origin,
"CLUSTERSMCTR", iLayer, Lifetime::Timeframe);
312 outputs.emplace_back(Origin,
"CLUSTERSMC2ROF", iLayer, Lifetime::Timeframe);
316 .
name = (N == o2::detectors::DetID::ITS) ?
"its-clusterer" :
"mft-clusterer",
321 {
"ignore-cluster-dictionary", VariantType::Bool,
false, {
"do not use cluster dictionary, always store explicit patterns"}},
322 {
"nthreads", VariantType::Int, 1, {
"Number of clustering threads"}}}};
328 return getClustererSpec<o2::detectors::DetID::ITS>(useMC, doStag);
333 return getClustererSpec<o2::detectors::DetID::MFT>(useMC, doStag);
Definition of the ITSMFT compact cluster.
A const (ready only) version of MCTruthContainer.
Definition of the Names Generator class.
Definition of the GeometryManager class.
Definition of the Alpide pixel reader for MC digits processing.
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
Header of the General Run Parameters object.
Definition of the ITS/MFT clusterer settings.
std::vector< o2::MCCompLabel > labels
Header to collect LHC related constants.
void checkUpdates(o2::framework::ProcessingContext &pc)
static int getNHBFPerTF()
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
static const DPLAlpideParam< N > & Instance()
T get(const char *key) const
void snapshot(const Output &spec, T const &object)
ConfigParamRegistry const & options()
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
ServiceRegistryRef services()
The services registry associated with this processing context.
static constexpr int getNChips()
number of chips per barrel
static constexpr Int_t getNChips()
void init(InitContext &ic) final
ClustererDPL(std::shared_ptr< o2::base::GRPGeomRequest > gr, bool useMC, bool doStag)
void finaliseCCDB(ConcreteDataMatcher &matcher, void *obj) final
void run(ProcessingContext &pc) final
void setDigitsMCTruth(const o2::dataformats::ConstMCTruthContainerView< o2::MCCompLabel > *m)
void setDigits(const gsl::span< const o2::itsmft::Digit > a)
void setSquashingDist(const int16_t v)
void setMaxBCSeparationToSquash(int n)
void setROFRecords(const gsl::span< const o2::itsmft::ROFRecord > a)
void setSquashingDepth(const int16_t v)
GLenum GLuint GLint GLint layer
constexpr o2::header::DataOrigin gDataOriginMFT
constexpr o2::header::DataOrigin gDataOriginITS
AlgorithmSpec adaptFromTask(Args &&... args)
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
const bool const int nLayers
framework::DataProcessorSpec getMFTClustererSpec(bool useMC, bool doStag)
framework::DataProcessorSpec getITSClustererSpec(bool useMC, bool doStag)
std::string asString() const
static bool match(DataRef const &ref, const char *binding)
static constexpr int getNLayers()
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
o2::InteractionRecord ir(0, 0)
std::vector< Digit > digits