Project
Loading...
Searching...
No Matches
SecondaryVertexingSpec.cxx
Go to the documentation of this file.
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
13
14#include <TMap.h>
15#include <TObjString.h>
16#include <vector>
34#include "TStopwatch.h"
36#include "TPCFastTransformPOD.h"
39
40using namespace o2::framework;
41
51
52namespace o2
53{
54namespace vertexing
55{
56
57namespace o2d = o2::dataformats;
58
60{
61 public:
62 SecondaryVertexingSpec(std::shared_ptr<DataRequest> dr, std::shared_ptr<o2::base::GRPGeomRequest> gr, GTrackID::mask_t src, bool enabCasc, bool enable3body, bool enableStrangenessTracking, bool enableCCDBParams, bool useMC) : mDataRequest(dr), mGGCCDBRequest(gr), mSrc(src), mEnableCascades(enabCasc), mEnable3BodyVertices(enable3body), mEnableStrangenessTracking(enableStrangenessTracking), mEnableCCDBParams(enableCCDBParams), mUseMC(useMC) {}
63 ~SecondaryVertexingSpec() override = default;
64 void init(InitContext& ic) final;
65 void run(ProcessingContext& pc) final;
66 void endOfStream(EndOfStreamContext& ec) final;
67 void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) final;
68
69 private:
70 void storeConfigs(ProcessingContext& pc);
71 void updateTimeDependentParams(ProcessingContext& pc);
72 std::shared_ptr<DataRequest> mDataRequest;
73 std::shared_ptr<o2::base::GRPGeomRequest> mGGCCDBRequest;
74 o2::tpc::VDriftHelper mTPCVDriftHelper{};
75 const o2::gpu::TPCFastTransformPOD* mTPCCorrMaps{nullptr};
76 GTrackID::mask_t mSrc{};
77 bool mEnableCCDBParams = false;
78 bool mEnableCascades = false;
79 bool mEnable3BodyVertices = false;
80 bool mEnableStrangenessTracking = false;
81 bool mUseMC = false;
84 TStopwatch mTimer;
85};
86
88{
89 mTimer.Stop();
90 mTimer.Reset();
92 //-------- init geometry and field --------//
93 mVertexer.setEnableCascades(mEnableCascades);
94 mVertexer.setEnable3BodyDecays(mEnable3BodyVertices);
95 mVertexer.setNThreads(ic.options().get<int>("threads"));
96 mVertexer.setUseMC(mUseMC);
97 if (mEnableStrangenessTracking) {
100 mStrTracker.setupThreads(ic.options().get<int>("threads"));
101 mStrTracker.setupFitters();
102 mStrTracker.setMCTruthOn(mUseMC);
103 mVertexer.setStrangenessTracker(&mStrTracker);
104 }
105}
106
108{
109 double timeCPU0 = mTimer.CpuTime(), timeReal0 = mTimer.RealTime();
110 mTimer.Start(false);
111 static std::array<size_t, 3> fitCalls{};
112
114 recoData.collectData(pc, *mDataRequest.get());
115 updateTimeDependentParams(pc);
116 storeConfigs(pc);
117 mVertexer.process(recoData, pc);
118
119 mTimer.Stop();
120 auto calls = mVertexer.getNFitterCalls();
121 LOGP(info, "Found {} V0s ({} fits), {} cascades ({} fits), {} 3-body decays ({} fits), {} strange tracks. Timing: CPU: {:.2f} Real: {:.2f} s",
122 mVertexer.getNV0s(), calls[0] - fitCalls[0], mVertexer.getNCascades(), calls[1] - fitCalls[1], mVertexer.getN3Bodies(), calls[2] - fitCalls[2], mVertexer.getNStrangeTracks(),
123 mTimer.CpuTime() - timeCPU0, mTimer.RealTime() - timeReal0);
124 fitCalls = calls;
125}
126
127void SecondaryVertexingSpec::storeConfigs(ProcessingContext& pc)
128{
129 static bool first = true;
130 if (first) {
131 first = false;
133 const auto& confSV = SVertexerParams::Instance();
135 TMap md;
136 md.SetOwnerKeyValue();
137 md.Add(new TObjString(confSV.getName().c_str()), new TObjString(o2::conf::ConfigurableParam::asJSON(confSV.getName()).c_str()));
138 if (mEnableStrangenessTracking) {
141 md.Add(new TObjString(confST.getName().c_str()), new TObjString(o2::conf::ConfigurableParam::asJSON(confST.getName()).c_str()));
142 }
143 pc.outputs().snapshot(Output{"META", "SVERTEXER", 0}, md);
144 }
145 }
146}
147
149{
150 LOGF(info, "Secondary vertexing total timing: Cpu: %.3e Real: %.3e s in %d slots, nThreads = %d",
151 mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1, mVertexer.getNThreads());
152}
153
155{
157 return;
158 }
159 if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) {
160 return;
161 }
162 if (matcher == ConcreteDataMatcher("ITS", "CLUSDICT", 0)) {
163 LOG(info) << "cluster dictionary updated";
165 return;
166 }
167 if (matcher == ConcreteDataMatcher("GLO", "MEANVERTEX", 0)) {
168 LOG(info) << "Imposing new MeanVertex: " << ((const o2::dataformats::MeanVertexObject*)obj)->asString();
170 return;
171 }
172 if (matcher == ConcreteDataMatcher("GLO", "SVPARAM", 0)) {
173 LOG(info) << "SVertexer Params updated from ccdb";
174 return;
175 }
176 if (matcher == ConcreteDataMatcher("ITS", "GEOMTGEO", 0)) {
177 LOG(info) << "ITS GeomtetryTGeo loaded from ccdb";
179 return;
180 }
181#ifdef ENABLE_UPGRADES
182 if (matcher == ConcreteDataMatcher("IT3", "CLUSDICT", 0)) {
183 LOG(info) << "cluster dictionary updated";
184 mStrTracker.setClusterDictionaryIT3((const o2::its3::TopologyDictionary*)obj);
185 return;
186 }
187#endif
188}
189
190void SecondaryVertexingSpec::updateTimeDependentParams(ProcessingContext& pc)
191{
193 if (mSrc[GTrackID::TPC]) {
194 mTPCVDriftHelper.extractCCDBInputs(pc);
195 auto const& raw = pc.inputs().get<const char*>("corrMap");
196 mTPCCorrMaps = &gpu::TPCFastTransformPOD::get(raw);
197 }
198 static bool initOnceDone = false;
199 if (!initOnceDone) { // this params need to be queried only once
200 initOnceDone = true;
201 mVertexer.init();
202 if (mEnableCCDBParams) {
203 // for reading the calib objects from the CCDB
204 pc.inputs().get<o2::vertexing::SVertexerParams*>("SVParam");
205 }
206 if (pc.services().get<const o2::framework::DeviceSpec>().inputTimesliceId == 0) {
207 // setting and or overwriting the configurable params
209 }
210 if (pc.inputs().getPos("itsTGeo") >= 0) {
211 pc.inputs().get<o2::its::GeometryTGeo*>("itsTGeo");
212 }
213 if (mEnableStrangenessTracking) {
216 }
217
218#ifdef ENABLE_UPGRADES
219 if (o2::GlobalParams::Instance().withITS3) { // hack to trigger loading dictionary
220 pc.inputs().get<o2::its3::TopologyDictionary*>("cldict");
221 }
222#endif
223 }
224 // we may have other params which need to be queried regularly
225 if (mSrc[GTrackID::TPC]) {
226 mVertexer.setTPCCorrMaps(mTPCCorrMaps);
227
228 if (mTPCVDriftHelper.isUpdated()) {
229 LOGP(info, "Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}",
230 mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift,
231 mTPCVDriftHelper.getVDriftObject().timeOffsetCorr, mTPCVDriftHelper.getVDriftObject().refTimeOffset,
232 mTPCVDriftHelper.getSourceName());
233 mVertexer.setTPCVDrift(mTPCVDriftHelper.getVDriftObject());
234 mTPCVDriftHelper.acknowledgeUpdate();
235 }
236 }
237 if (mEnableStrangenessTracking) {
238 if (o2::base::Propagator::Instance()->getNominalBz() != mStrTracker.getBz()) {
239 mStrTracker.setBz(o2::base::Propagator::Instance()->getNominalBz());
240 mStrTracker.setupFitters();
241 }
242 }
243
245}
246
247DataProcessorSpec getSecondaryVertexingSpec(GTrackID::mask_t src, bool enableCasc, bool enable3body, bool enableStrangenesTracking, bool enableCCDBParams,
248 bool useMC, bool useGeom)
249{
250 std::vector<OutputSpec> outputs;
251 Options opts{
252 {"material-lut-path", VariantType::String, "", {"Path of the material LUT file"}},
253 {"threads", VariantType::Int, 1, {"Number of threads"}}};
254 auto dataRequest = std::make_shared<DataRequest>();
255 if (enableCCDBParams) {
256 dataRequest->inputs.emplace_back("SVParam", "GLO", "SVPARAM", 0, Lifetime::Condition, ccdbParamSpec("GLO/Config/SVertexerParam"));
257 }
258 GTrackID::mask_t srcClus{};
259 if (enableStrangenesTracking) {
260 src |= (srcClus = GTrackID::getSourceMask(GTrackID::ITS));
261 }
262 if (GTrackID::includesDet(o2::detectors::DetID::TPC, src) && !src[GTrackID::TPC]) {
263 LOGP(warn, "Tracks involving TPC were requested w/o requesting TPC-only tracks, simplified selection will be applied");
264 }
265 if (src[GTrackID::TPC]) {
266 srcClus |= GTrackID::getSourceMask(GTrackID::TPC);
267 }
268 if (srcClus.any()) {
269 dataRequest->requestClusters(srcClus, useMC);
270 }
271#ifdef ENABLE_UPGRADES
272 if (o2::GlobalParams::Instance().withITS3) { // hack to trigger loading dictionary
273 dataRequest->inputs.emplace_back("cldict", "IT3", "CLUSDICT", Lifetime::Condition, ccdbParamSpec("IT3/Calib/ClusterDictionary"));
274 }
275#endif
276 dataRequest->requestTracks(src, useMC);
277 dataRequest->requestPrimaryVertices(useMC);
278 dataRequest->inputs.emplace_back("meanvtx", "GLO", "MEANVERTEX", 0, Lifetime::Condition, ccdbParamSpec("GLO/Calib/MeanVertex", {}, 1));
279 auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(false, // orbitResetTime
280 true, // GRPECS=true
281 false, // GRPLHCIF
282 true, // GRPMagField
283 true, // askMatLUT
284 useGeom || enableStrangenesTracking ? o2::base::GRPGeomRequest::Aligned : o2::base::GRPGeomRequest::None, // geometry
285 dataRequest->inputs,
286 true);
287 if (!useGeom && enableStrangenesTracking) {
288 ggRequest->addInput({"itsTGeo", "ITS", "GEOMTGEO", 0, Lifetime::Condition, framework::ccdbParamSpec("ITS/Config/Geometry")}, dataRequest->inputs);
289 }
290 if (src[GTrackID::TPC]) {
291 o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs);
292 dataRequest->inputs.emplace_back("corrMap", o2::header::gDataOriginTPC, "TPCCORRMAP", 0, Lifetime::Timeframe);
293 }
294 outputs.emplace_back("GLO", "V0S_IDX", 0, Lifetime::Timeframe); // found V0s indices
295 outputs.emplace_back("GLO", "V0S", 0, Lifetime::Timeframe); // found V0s
296 outputs.emplace_back("GLO", "PVTX_V0REFS", 0, Lifetime::Timeframe); // prim.vertex -> V0s refs
297
298 outputs.emplace_back("GLO", "CASCS_IDX", 0, Lifetime::Timeframe); // found Cascades indices
299 outputs.emplace_back("GLO", "CASCS", 0, Lifetime::Timeframe); // found Cascades
300 outputs.emplace_back("GLO", "PVTX_CASCREFS", 0, Lifetime::Timeframe); // prim.vertex -> Cascades refs
301
302 outputs.emplace_back("GLO", "DECAYS3BODY_IDX", 0, Lifetime::Timeframe); // found 3 body vertices indices
303 outputs.emplace_back("GLO", "DECAYS3BODY", 0, Lifetime::Timeframe); // found 3 body vertices
304 outputs.emplace_back("GLO", "PVTX_3BODYREFS", 0, Lifetime::Timeframe); // prim.vertex -> 3 body vertices refs
305
306 if (enableStrangenesTracking) {
307 outputs.emplace_back("GLO", "STRANGETRACKS", 0, Lifetime::Timeframe); // found strange track
308 outputs.emplace_back("GLO", "CLUSUPDATES", 0, Lifetime::Timeframe);
309 if (useMC) {
310 outputs.emplace_back("GLO", "STRANGETRACKS_MC", 0, Lifetime::Timeframe);
311 LOG(info) << "Strangeness tracker will use MC";
312 }
313 }
314 outputs.emplace_back("META", "SVERTEXER", 0, Lifetime::Sporadic);
315
316 return DataProcessorSpec{
317 "secondary-vertexing",
318 dataRequest->inputs,
319 outputs,
320 AlgorithmSpec{adaptFromTask<SecondaryVertexingSpec>(dataRequest, ggRequest, src, enableCasc, enable3body, enableStrangenesTracking, enableCCDBParams, useMC)},
321 opts};
322}
323
324} // namespace vertexing
325} // namespace o2
Wrapper container for different reconstructed object types.
Definition of the GeometryManager class.
o2::raw::RawFileWriter * raw
Helper for geometry and GRP related CCDB requests.
Global index for barrel track: provides provenance (detectors combination), index in respective array...
Definition of the Names Generator class.
Secondary vertex finder.
POD correction map.
Definition of the ITS track.
Result of refitting TPC-ITS matched track.
Helper class to extract VDrift from different sources.
void checkUpdates(o2::framework::ProcessingContext &pc)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
static std::string getConfigOutputFileName(const std::string &procName, const std::string &confName="", bool json=true)
Definition NameConf.cxx:120
GPUd() value_type estimateLTFast(o2 static GPUd() float estimateLTIncrement(const o2 PropagatorImpl * Instance(bool uninitialized=false)
Definition Propagator.h:178
void printKeyValues(bool showProv=true, bool useLogger=false, bool withPadding=true, bool showHash=true) const final
static std::string asJSON(std::string const &keyOnly="")
static void write(std::string const &filename, std::string const &keyOnly="")
TO BE DONE: extend to generic N body vertex.
Definition Decay3Body.h:26
static constexpr ID TPC
Definition DetID.h:64
void snapshot(const Output &spec, T const &object)
ConfigParamRegistry const & options()
Definition InitContext.h:33
int getPos(const char *name) const
decltype(auto) get(R binding, int part=0) const
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 GeometryTGeo * Instance()
void fillMatrixCache(int mask) override
static void adopt(GeometryTGeo *raw, bool canDelete=false)
void setConfigParams(const StrangenessTrackingParamConfig *params)
void setCorrType(const o2::base::PropagatorImpl< float >::MatCorrType &type)
void setClusterDictionaryITS(const o2::itsmft::TopologyDictionary *d)
static void requestCCDBInputs(std::vector< o2::framework::InputSpec > &inputs, bool laser=true, bool itstpcTgl=true)
void extractCCDBInputs(o2::framework::ProcessingContext &pc, bool laser=true, bool itstpcTgl=true)
const VDriftCorrFact & getVDriftObject() const
bool accountCCDBInputs(const o2::framework::ConcreteDataMatcher &matcher, void *obj)
static std::string_view getSourceName(Source s)
bool isUpdated() const
void setEnableCascades(bool v)
Definition SVertexer.h:116
std::array< size_t, 3 > getNFitterCalls() const
void setEnable3BodyDecays(bool v)
Definition SVertexer.h:117
void setTPCCorrMaps(const o2::gpu::TPCFastTransformPOD *maph)
void process(const o2::globaltracking::RecoContainer &recoTracks, o2::framework::ProcessingContext &pc)
Definition SVertexer.cxx:42
void setTPCVDrift(const o2::tpc::VDriftCorrFact &v)
void setMeanVertex(const o2::dataformats::MeanVertexObject *v)
Definition SVertexer.h:126
void setStrangenessTracker(o2::strangeness_tracking::StrangenessTracker *tracker)
Definition SVertexer.h:146
int getNStrangeTracks() const
Definition SVertexer.h:124
~SecondaryVertexingSpec() override=default
SecondaryVertexingSpec(std::shared_ptr< DataRequest > dr, std::shared_ptr< o2::base::GRPGeomRequest > gr, GTrackID::mask_t src, bool enabCasc, bool enable3body, bool enableStrangenessTracking, bool enableCCDBParams, bool useMC)
void finaliseCCDB(ConcreteDataMatcher &matcher, void *obj) final
void endOfStream(EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void run(ProcessingContext &pc) final
GLenum src
Definition glcorearb.h:1767
constexpr o2::header::DataOrigin gDataOriginTPC
Definition DataHeader.h:576
Definition of a container to keep/associate and arbitrary number of labels associated to an index wit...
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
std::vector< ConfigParamSpec > Options
o2::framework::DataProcessorSpec getSecondaryVertexingSpec(o2::dataformats::GlobalTrackID::mask_t src, bool enableCasc, bool enable3body, bool enableStrangenesTracking, bool enableCCDBParams, bool useMC, bool useGeom)
create a processor spec
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string name
The name of the associated DataProcessorSpec.
Definition DeviceSpec.h:50
size_t inputTimesliceId
The time pipelining id of this particular device.
Definition DeviceSpec.h:68
void collectData(o2::framework::ProcessingContext &pc, const DataRequest &request)
static constexpr int T2L
Definition Cartesian.h:55
static constexpr int T2GRot
Definition Cartesian.h:57
static constexpr int T2G
Definition Cartesian.h:56
float refTimeOffset
additive time offset reference (\mus)
float refVDrift
reference vdrift for which factor was extracted
float timeOffsetCorr
additive time offset correction (\mus)
float corrFact
drift velocity correction factor (multiplicative)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"