forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathO2DPLDisplay.cxx
More file actions
208 lines (179 loc) · 8.99 KB
/
O2DPLDisplay.cxx
File metadata and controls
208 lines (179 loc) · 8.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include "EveWorkflow/O2DPLDisplay.h"
#include "EveWorkflow/FileProducer.h"
#include "EventVisualisationDataConverter/VisualisationTrack.h"
#include "EventVisualisationDataConverter/VisualisationEvent.h"
#include "Framework/ConfigParamSpec.h"
#include "DataFormatsParameters/GRPObject.h"
#include "DataFormatsGlobalTracking/RecoContainer.h"
#include "DetectorsCommonDataFormats/NameConf.h"
#include "DetectorsBase/GeometryManager.h"
#include "TRDBase/GeometryFlat.h"
#include "TRDBase/Geometry.h"
#include "TOFBase/Geo.h"
#include "ITSBase/GeometryTGeo.h"
#include "DetectorsBase/Propagator.h"
#include "GPUO2InterfaceDisplay.h"
#include "GPUO2InterfaceConfiguration.h"
#include "TPCFastTransform.h"
#include "TPCReconstruction/TPCFastTransformHelperO2.h"
#include "GlobalTrackingWorkflowHelpers/InputHelper.h"
#include "DataFormatsTPC/WorkflowHelper.h"
#include "DataFormatsTRD/RecoInputContainer.h"
#include "GPUWorkflowHelper/GPUWorkflowHelper.h"
#include "DataFormatsITSMFT/TopologyDictionary.h"
using namespace o2::framework;
using namespace o2::dataformats;
using namespace o2::globaltracking;
using namespace o2::gpu;
using namespace o2::tpc;
using namespace o2::trd;
void customize(std::vector<ConfigParamSpec>& workflowOptions)
{
std::vector<o2::framework::ConfigParamSpec> options{
{"enable-mc", o2::framework::VariantType::Bool, false, {"enable visualization of MC data"}},
{"disable-mc", o2::framework::VariantType::Bool, false, {"disable visualization of MC data"}}, // for compatibility, overrides enable-mc
{"display-clusters", VariantType::String, "ITS,TPC,TRD,TOF", {"comma-separated list of clusters to display"}},
{"display-tracks", VariantType::String, "TPC,ITS,ITS-TPC,TPC-TRD,ITS-TPC-TRD,TPC-TOF,ITS-TPC-TOF", {"comma-separated list of tracks to display"}},
{"read-from-files", o2::framework::VariantType::Bool, false, {"comma-separated list of tracks to display"}},
{"disable-root-input", o2::framework::VariantType::Bool, false, {"Disable root input overriding read-from-files"}},
{"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings ..."}}};
std::swap(workflowOptions, options);
}
#include "Framework/runDataProcessing.h"
void O2GPUDPLDisplaySpec::init(InitContext& ic)
{
const auto grp = o2::parameters::GRPObject::loadFrom();
o2::base::GeometryManager::loadGeometry();
o2::base::Propagator::initFieldFromGRP();
mConfig.reset(new GPUO2InterfaceConfiguration);
mConfig->configGRP.solenoidBz = 5.00668f * grp->getL3Current() / 30000.;
mConfig->configGRP.continuousMaxTimeBin = grp->isDetContinuousReadOut(o2::detectors::DetID::TPC) ? -1 : 0; // Number of timebins in timeframe if continuous, 0 otherwise
mConfig->ReadConfigurableParam();
mFastTransform = std::move(TPCFastTransformHelperO2::instance()->create(0));
mConfig->configCalib.fastTransform = mFastTransform.get();
auto gm = o2::trd::Geometry::instance();
gm->createPadPlaneArray();
gm->createClusterMatrixArray();
mTrdGeo.reset(new o2::trd::GeometryFlat(*gm));
mConfig->configCalib.trdGeometry = mTrdGeo.get();
mITSDict = std::make_unique<o2::itsmft::TopologyDictionary>();
mConfig->configCalib.itsPatternDict = mITSDict.get();
mConfig->configProcessing.runMC = mUseMC;
o2::tof::Geo::Init();
o2::its::GeometryTGeo::Instance()->fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::T2GRot, o2::math_utils::TransformType::T2G, o2::math_utils::TransformType::L2G, o2::math_utils::TransformType::T2L));
//mDisplay.reset(new GPUO2InterfaceDisplay(mConfig.get()));
}
struct GPUWorkflowHelper::tmpDataContainer {
std::vector<o2::BaseCluster<float>> ITSClustersArray;
std::vector<int> tpcLinkITS, tpcLinkTRD, tpcLinkTOF;
std::vector<const o2::track::TrackParCov*> globalTracks;
std::vector<float> globalTrackTimes;
};
using GID = o2::dataformats::GlobalTrackID;
using PNT = std::array<float, 3>;
std::vector<PNT> getTrackPoints(const o2::track::TrackPar& trc, float minR, float maxR, float maxStep)
{
// prepare space points from the track param
std::vector<PNT> pnts;
int nSteps = std::max(2, int((maxR - minR) / maxStep));
const auto prop = o2::base::Propagator::Instance();
float xMin = trc.getX(), xMax = maxR * maxR - trc.getY() * trc.getY();
if (xMax > 0) {
xMax = std::sqrt(xMax);
}
LOG(INFO) << "R: " << minR << " " << maxR << " || X: " << xMin << " " << xMax;
float dx = (xMax - xMin) / nSteps;
auto tp = trc;
float dxmin = std::abs(xMin - tp.getX()), dxmax = std::abs(xMax - tp.getX());
bool res = false;
if (dxmin > dxmax) { //start from closest end
std::swap(xMin, xMax);
dx = -dx;
}
if (!prop->propagateTo(tp, xMin, false, 0.99, maxStep, o2::base::PropagatorF::MatCorrType::USEMatCorrNONE)) {
return pnts;
}
auto xyz = tp.getXYZGlo();
pnts.emplace_back(PNT{xyz.X(), xyz.Y(), xyz.Z()});
for (int is = 0; is < nSteps; is++) {
if (!prop->propagateTo(tp, tp.getX() + dx, false, 0.99, 999., o2::base::PropagatorF::MatCorrType::USEMatCorrNONE)) {
return pnts;
}
xyz = tp.getXYZGlo();
pnts.emplace_back(PNT{xyz.X(), xyz.Y(), xyz.Z()});
}
return pnts;
}
void O2GPUDPLDisplaySpec::run(ProcessingContext& pc)
{
o2::globaltracking::RecoContainer recoData;
recoData.collectData(pc, *mDataRequest);
GPUTrackingInOutPointers ptrs;
auto cnt = GPUWorkflowHelper::fillIOPtr(ptrs, recoData, mUseMC, &(mConfig->configCalib), mClMask, mTrkMask, mTrkMask);
std::cout << cnt->globalTracks.size() << std::endl;
o2::event_visualisation::VisualisationEvent vEvent;
for (int i = 0; i < cnt->globalTracks.size(); i++) {
auto tr = cnt->globalTracks[i];
std::cout << tr->getX() << std::endl;
float rMax = 385;
float rMin = std::sqrt(tr->getX() * tr->getX() + tr->getY() * tr->getY());
auto pnts = getTrackPoints(*tr, rMin, rMax, 4.0);
o2::event_visualisation::VisualisationTrack* vTrack = vEvent.addTrack({.charge = 0,
.energy = 0.0,
.ID = 0,
.PID = 0,
.mass = 0.0,
.signedPT = 0.0,
.startXYZ = {0, 0, 0},
.endXYZ = {0, 0, 0},
.pxpypz = {0, 0, 0},
.parentID = 0,
.phi = 0.0,
.theta = 0.0,
.helixCurvature = 0.0,
.type = 0,
.source = CosmicSource});
float dz = 0.0;
for (size_t ip = 0; ip < pnts.size(); ip++) {
vTrack->addPolyPoint(pnts[ip][0], pnts[ip][1], pnts[ip][2] + dz);
}
}
FileProducer producer("./jsons");
vEvent.toFile(producer.newFileName());
}
void O2GPUDPLDisplaySpec::endOfStream(EndOfStreamContext& ec)
{
}
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
{
WorkflowSpec specs;
o2::conf::ConfigurableParam::updateFromString(cfgc.options().get<std::string>("configKeyValues"));
bool useMC = cfgc.options().get<bool>("enable-mc") && !cfgc.options().get<bool>("disable-mc");
GlobalTrackID::mask_t srcTrk = GlobalTrackID::getSourcesMask(cfgc.options().get<std::string>("display-tracks"));
GlobalTrackID::mask_t srcCl = GlobalTrackID::getSourcesMask(cfgc.options().get<std::string>("display-clusters"));
if (!srcTrk.any() && !srcCl.any()) {
throw std::runtime_error("No input configured");
}
std::shared_ptr<DataRequest> dataRequest = std::make_shared<DataRequest>();
dataRequest->requestTracks(srcTrk, useMC);
dataRequest->requestClusters(srcCl, useMC);
if (cfgc.options().get<bool>("read-from-files")) {
InputHelper::addInputSpecs(cfgc, specs, srcCl, srcTrk, srcTrk, useMC);
}
specs.emplace_back(DataProcessorSpec{
"o2-gpu-display",
dataRequest->inputs,
{},
AlgorithmSpec{adaptFromTask<O2GPUDPLDisplaySpec>(useMC, srcTrk, srcCl, dataRequest)}});
return std::move(specs);
}