|
| 1 | +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. |
| 2 | +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 3 | +// All rights not expressly granted are reserved. |
| 4 | +// |
| 5 | +// This software is distributed under the terms of the GNU General Public |
| 6 | +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 7 | +// |
| 8 | +// In applying this license CERN does not waive the privileges and immunities |
| 9 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 10 | +// or submit itself to any jurisdiction. |
| 11 | + |
| 12 | +/// @file CATrackerSpec.cxx |
| 13 | + |
| 14 | +#include "MFTWorkflow/CATrackerSpec.h" |
| 15 | + |
| 16 | +#include <vector> |
| 17 | + |
| 18 | +#include <gsl/span> |
| 19 | + |
| 20 | +#include "CommonConstants/LHCConstants.h" |
| 21 | +#include "CommonDataFormat/IRFrame.h" |
| 22 | +#include "DataFormatsITSMFT/CompCluster.h" |
| 23 | +#include "DataFormatsITSMFT/DPLAlpideParam.h" |
| 24 | +#include "DataFormatsITSMFT/ROFRecord.h" |
| 25 | +#include "DataFormatsITSMFT/TopologyDictionary.h" |
| 26 | +#include "DataFormatsParameters/GRPObject.h" |
| 27 | +#include "DetectorsBase/GeometryManager.h" |
| 28 | +#include "DetectorsCommonDataFormats/DetectorNameConf.h" |
| 29 | +#include "Framework/CCDBParamSpec.h" |
| 30 | +#include "Framework/ConfigParamRegistry.h" |
| 31 | +#include "Framework/ControlService.h" |
| 32 | +#include "Framework/DataProcessorSpec.h" |
| 33 | +#include "Framework/DeviceSpec.h" |
| 34 | +#include "Framework/Logger.h" |
| 35 | +#include "MFTBase/GeometryTGeo.h" |
| 36 | +#include "SimulationDataFormat/MCCompLabel.h" |
| 37 | +#include "SimulationDataFormat/MCTruthContainer.h" |
| 38 | + |
| 39 | +using namespace o2::framework; |
| 40 | + |
| 41 | +namespace o2::mft |
| 42 | +{ |
| 43 | + |
| 44 | +void CATrackerDPL::init(InitContext&) |
| 45 | +{ |
| 46 | + o2::base::GRPGeomHelper::instance().setRequest(mGGCCDBRequest); |
| 47 | +} |
| 48 | + |
| 49 | +void CATrackerDPL::run(ProcessingContext& pc) |
| 50 | +{ |
| 51 | + updateTimeDependentParams(pc); |
| 52 | + |
| 53 | + auto compClusters = pc.inputs().get<const std::vector<o2::itsmft::CompClusterExt>>("compClusters"); |
| 54 | + gsl::span<const unsigned char> patterns = pc.inputs().get<gsl::span<unsigned char>>("patterns"); |
| 55 | + auto rofs = pc.inputs().get<const std::vector<o2::itsmft::ROFRecord>>("ROframes"); |
| 56 | + initialiseROFTable(gsl::span<const o2::itsmft::ROFRecord>(rofs.data(), rofs.size())); |
| 57 | + |
| 58 | + const dataformats::MCTruthContainer<MCCompLabel>* labels = nullptr; |
| 59 | + if (mUseMC) { |
| 60 | + labels = pc.inputs().get<const dataformats::MCTruthContainer<MCCompLabel>*>("labels").release(); |
| 61 | + } |
| 62 | + |
| 63 | + LOGP(info, "MFT CA input pulled {} compressed clusters, {} pattern bytes, {} RO frames, dictionary={}, MC labels={}", |
| 64 | + compClusters.size(), patterns.size(), rofs.size(), mDict != nullptr, labels != nullptr); |
| 65 | + |
| 66 | + size_t nClusterRefs = 0; |
| 67 | + for (const auto& rof : rofs) { |
| 68 | + nClusterRefs += rof.getNEntries(); |
| 69 | + } |
| 70 | + LOGP(info, "MFT CA input ROF cluster references: {}", nClusterRefs); |
| 71 | + |
| 72 | + if (pc.inputs().getPos("IRFramesITS") >= 0) { |
| 73 | + auto irFrames = pc.inputs().get<gsl::span<o2::dataformats::IRFrame>>("IRFramesITS"); |
| 74 | + LOGP(info, "MFT CA input pulled {} ITS IR frames", irFrames.size()); |
| 75 | + } |
| 76 | + |
| 77 | + // Next step: replace this inspection point with a loader into a generalized |
| 78 | + // ITS TimeFrame interface that accepts MFT layer geometry and cluster data. |
| 79 | +} |
| 80 | + |
| 81 | +void CATrackerDPL::updateTimeDependentParams(ProcessingContext& pc) |
| 82 | +{ |
| 83 | + o2::base::GRPGeomHelper::instance().checkUpdates(pc); |
| 84 | + static bool initOnceDone = false; |
| 85 | + if (!initOnceDone) { |
| 86 | + initOnceDone = true; |
| 87 | + if (pc.inputs().getPos("mftTGeo") >= 0) { |
| 88 | + pc.inputs().get<o2::mft::GeometryTGeo*>("mftTGeo"); |
| 89 | + } |
| 90 | + pc.inputs().get<o2::itsmft::TopologyDictionary*>("cldict"); |
| 91 | + o2::mft::GeometryTGeo::Instance()->fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::T2L, |
| 92 | + o2::math_utils::TransformType::T2GRot, |
| 93 | + o2::math_utils::TransformType::T2G)); |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +void CATrackerDPL::initialiseROFTable(gsl::span<const o2::itsmft::ROFRecord> rofs) |
| 98 | +{ |
| 99 | + if (!o2::base::GRPGeomHelper::instance().getGRPECS()->isDetContinuousReadOut(o2::detectors::DetID::MFT)) { |
| 100 | + LOGP(fatal, "MFT CA tracker currently supports only continuous readout"); |
| 101 | + } |
| 102 | + |
| 103 | + const auto& par = o2::itsmft::DPLAlpideParam<o2::detectors::DetID::MFT>::Instance(); |
| 104 | + const int nOrbitsPerTF = o2::base::GRPGeomHelper::getNHBFPerTF(); |
| 105 | + const int timingSourceLayer = 0; // MFT CA disks share timing for now; keep per-CA-layer definition for future staggering. |
| 106 | + const unsigned int nROFsPerOrbit = o2::constants::lhc::LHCMaxBunches / par.getROFLengthInBC(timingSourceLayer); |
| 107 | + const auto nROFsTF = nROFsPerOrbit * nOrbitsPerTF; |
| 108 | + |
| 109 | + ROFOverlapTable rofTable; |
| 110 | + for (int caLayer = 0; caLayer < NCALayers; ++caLayer) { |
| 111 | + const o2::its::LayerTiming timing{ |
| 112 | + .mNROFsTF = nROFsTF, |
| 113 | + .mROFLength = static_cast<uint32_t>(par.getROFLengthInBC(timingSourceLayer)), |
| 114 | + .mROFDelay = static_cast<uint32_t>(par.getROFDelayInBC(timingSourceLayer)), |
| 115 | + .mROFBias = static_cast<uint32_t>(par.getROFBiasInBC(timingSourceLayer)), |
| 116 | + .mROFAddTimeErr = 0}; |
| 117 | + rofTable.defineLayer(caLayer, timing); |
| 118 | + } |
| 119 | + rofTable.init(); |
| 120 | + mROFTable = std::move(rofTable); |
| 121 | + mROFTableView = mROFTable.getView(); |
| 122 | + |
| 123 | + if (rofs.size() != nROFsTF) { |
| 124 | + LOGP(warn, "MFT CA ROF count differs from continuous timing expectation: received {} expected {}", rofs.size(), nROFsTF); |
| 125 | + } |
| 126 | + LOGP(info, "MFT CA ROF lookup table initialised for {} CA layers, {} ROFs/TF, ROF length {} BC, bias {} BC", |
| 127 | + NCALayers, nROFsTF, par.getROFLengthInBC(timingSourceLayer), par.getROFBiasInBC(timingSourceLayer)); |
| 128 | +} |
| 129 | + |
| 130 | +void CATrackerDPL::finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) |
| 131 | +{ |
| 132 | + if (o2::base::GRPGeomHelper::instance().finaliseCCDB(matcher, obj)) { |
| 133 | + return; |
| 134 | + } |
| 135 | + if (matcher == ConcreteDataMatcher("MFT", "CLUSDICT", 0)) { |
| 136 | + LOG(info) << "MFT CA input cluster dictionary updated"; |
| 137 | + mDict = static_cast<const o2::itsmft::TopologyDictionary*>(obj); |
| 138 | + return; |
| 139 | + } |
| 140 | + if (matcher == ConcreteDataMatcher("MFT", "GEOMTGEO", 0)) { |
| 141 | + LOG(info) << "MFT CA input GeometryTGeo loaded from CCDB"; |
| 142 | + o2::mft::GeometryTGeo::adopt(static_cast<o2::mft::GeometryTGeo*>(obj)); |
| 143 | + return; |
| 144 | + } |
| 145 | +} |
| 146 | + |
| 147 | +DataProcessorSpec getCATrackerSpec(bool useMC, bool useGeom, bool useIRFrames) |
| 148 | +{ |
| 149 | + std::vector<InputSpec> inputs; |
| 150 | + inputs.emplace_back("compClusters", "MFT", "COMPCLUSTERS", 0, Lifetime::Timeframe); |
| 151 | + inputs.emplace_back("patterns", "MFT", "PATTERNS", 0, Lifetime::Timeframe); |
| 152 | + inputs.emplace_back("ROframes", "MFT", "CLUSTERSROF", 0, Lifetime::Timeframe); |
| 153 | + inputs.emplace_back("cldict", "MFT", "CLUSDICT", 0, Lifetime::Condition, ccdbParamSpec("MFT/Calib/ClusterDictionary")); |
| 154 | + |
| 155 | + if (useMC) { |
| 156 | + inputs.emplace_back("labels", "MFT", "CLUSTERSMCTR", 0, Lifetime::Timeframe); |
| 157 | + } |
| 158 | + if (useIRFrames) { |
| 159 | + inputs.emplace_back("IRFramesITS", "ITS", "IRFRAMES", 0, Lifetime::Timeframe); |
| 160 | + } |
| 161 | + |
| 162 | + auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(false, // orbitResetTime |
| 163 | + true, // GRPECS=true |
| 164 | + false, // GRPLHCIF |
| 165 | + true, // GRPMagField |
| 166 | + false, // askMatLUT |
| 167 | + useGeom ? o2::base::GRPGeomRequest::Aligned : o2::base::GRPGeomRequest::None, // geometry |
| 168 | + inputs, |
| 169 | + true); |
| 170 | + if (!useGeom) { |
| 171 | + ggRequest->addInput({"mftTGeo", "MFT", "GEOMTGEO", 0, Lifetime::Condition, framework::ccdbParamSpec("MFT/Config/Geometry")}, inputs); |
| 172 | + } |
| 173 | + |
| 174 | + return DataProcessorSpec{ |
| 175 | + "mft-ca-tracker", |
| 176 | + inputs, |
| 177 | + {}, |
| 178 | + AlgorithmSpec{adaptFromTask<CATrackerDPL>(ggRequest, useMC)}, |
| 179 | + Options{}}; |
| 180 | +} |
| 181 | + |
| 182 | +} // namespace o2::mft |
0 commit comments