CMS 3D CMS Logo

PixelTrackProducerFromSoA.cc
Go to the documentation of this file.
23 
28 
32 
33 #include "storeTracks.h"
35 
41 public:
42  using IndToEdm = std::vector<uint16_t>;
43 
44  explicit PixelTrackProducerFromSoA(const edm::ParameterSet &iConfig);
45  ~PixelTrackProducerFromSoA() override = default;
46 
47  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
48 
49  // using HitModuleStart = std::array<uint32_t, gpuClustering::maxNumModules + 1>;
51 
52 private:
53  void produce(edm::StreamID streamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override;
54 
55  // Event Data tokens
60  // Event Setup tokens
63 
64  int32_t const minNumberOfHits_;
66 };
67 
69  : tBeamSpot_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot"))),
70  tokenTrack_(consumes<PixelTrackHeterogeneous>(iConfig.getParameter<edm::InputTag>("trackSrc"))),
71  cpuHits_(consumes<SiPixelRecHitCollectionNew>(iConfig.getParameter<edm::InputTag>("pixelRecHitLegacySrc"))),
72  hmsToken_(consumes<HMSstorage>(iConfig.getParameter<edm::InputTag>("pixelRecHitLegacySrc"))),
73  idealMagneticFieldToken_(esConsumes()),
74  ttTopoToken_(esConsumes()),
75  minNumberOfHits_(iConfig.getParameter<int>("minNumberOfHits")),
76  minQuality_(pixelTrack::qualityByName(iConfig.getParameter<std::string>("minQuality"))) {
78  throw cms::Exception("PixelTrackConfiguration")
79  << iConfig.getParameter<std::string>("minQuality") + " is not a pixelTrack::Quality";
80  }
82  throw cms::Exception("PixelTrackConfiguration")
83  << iConfig.getParameter<std::string>("minQuality") + " not supported";
84  }
85  produces<reco::TrackCollection>();
86  produces<TrackingRecHitCollection>();
87  produces<reco::TrackExtraCollection>();
88  produces<IndToEdm>();
89 }
90 
93  desc.add<edm::InputTag>("beamSpot", edm::InputTag("offlineBeamSpot"));
94  desc.add<edm::InputTag>("trackSrc", edm::InputTag("pixelTracksSoA"));
95  desc.add<edm::InputTag>("pixelRecHitLegacySrc", edm::InputTag("siPixelRecHitsPreSplittingLegacy"));
96  desc.add<int>("minNumberOfHits", 0);
97  desc.add<std::string>("minQuality", "loose");
98  descriptions.addWithDefaultLabel(desc);
99 }
100 
103  const edm::EventSetup &iSetup) const {
104  // enum class Quality : uint8_t { bad = 0, edup, dup, loose, strict, tight, highPurity };
113 
114  // std::cout << "Converting gpu helix in reco tracks" << std::endl;
115 
116  auto indToEdmP = std::make_unique<IndToEdm>();
117  auto &indToEdm = *indToEdmP;
118 
119  auto const &idealField = iSetup.getData(idealMagneticFieldToken_);
120 
122 
123  auto const &httopo = iSetup.getData(ttTopoToken_);
124 
125  const auto &bsh = iEvent.get(tBeamSpot_);
126  GlobalPoint bs(bsh.x0(), bsh.y0(), bsh.z0());
127 
128  auto const &rechits = iEvent.get(cpuHits_);
129  std::vector<TrackingRecHit const *> hitmap;
130  auto const &rcs = rechits.data();
131  auto nhits = rcs.size();
132  hitmap.resize(nhits, nullptr);
133 
134  auto const *hitsModuleStart = iEvent.get(hmsToken_).get();
135  auto fc = hitsModuleStart;
136 
137  for (auto const &h : rcs) {
138  auto const &thit = static_cast<BaseTrackerRecHit const &>(h);
139  auto detI = thit.det()->index();
140  auto const &clus = thit.firstClusterRef();
141  assert(clus.isPixel());
142  auto i = fc[detI] + clus.pixelCluster().originalId();
143  if (i >= hitmap.size())
144  hitmap.resize(i + 256, nullptr); // only in case of hit overflow in one module
145  assert(nullptr == hitmap[i]);
146  hitmap[i] = &h;
147  }
148 
149  std::vector<const TrackingRecHit *> hits;
150  hits.reserve(5);
151 
152  const auto &tsoa = *iEvent.get(tokenTrack_);
153 
154  auto const *quality = tsoa.qualityData();
155  auto const &fit = tsoa.stateAtBS;
156  auto const &hitIndices = tsoa.hitIndices;
157  auto nTracks = tsoa.nTracks();
158 
159  tracks.reserve(nTracks);
160 
161  int32_t nt = 0;
162 
163  //sort index by pt
164  std::vector<int32_t> sortIdxs(nTracks);
165  std::iota(sortIdxs.begin(), sortIdxs.end(), 0);
166  std::sort(
167  sortIdxs.begin(), sortIdxs.end(), [&](int32_t const i1, int32_t const i2) { return tsoa.pt(i1) > tsoa.pt(i2); });
168 
169  //store the index of the SoA: indToEdm[index_SoAtrack] -> index_edmTrack (if it exists)
170  indToEdm.resize(sortIdxs.size(), -1);
171  for (const auto &it : sortIdxs) {
172  auto nHits = tsoa.nHits(it);
173  assert(nHits >= 3);
174  auto q = quality[it];
175  if (q < minQuality_)
176  continue;
177  if (nHits < minNumberOfHits_)
178  continue;
179  indToEdm[it] = nt;
180  ++nt;
181 
182  hits.resize(nHits);
183  auto b = hitIndices.begin(it);
184  for (int iHit = 0; iHit < nHits; ++iHit)
185  hits[iHit] = hitmap[*(b + iHit)];
186 
187  // mind: this values are respect the beamspot!
188 
189  float chi2 = tsoa.chi2(it);
190  float phi = tsoa.phi(it);
191 
192  riemannFit::Vector5d ipar, opar;
193  riemannFit::Matrix5d icov, ocov;
194  fit.copyToDense(ipar, icov, it);
195  riemannFit::transformToPerigeePlane(ipar, icov, opar, ocov);
196 
197  LocalTrajectoryParameters lpar(opar(0), opar(1), opar(2), opar(3), opar(4), 1.);
199  for (int i = 0; i < 5; ++i)
200  for (int j = i; j < 5; ++j)
201  m(i, j) = ocov(i, j);
202 
203  float sp = std::sin(phi);
204  float cp = std::cos(phi);
205  Surface::RotationType rot(sp, -cp, 0, 0, 0, -1.f, cp, sp, 0);
206 
207  Plane impPointPlane(bs, rot);
209  impPointPlane.toGlobal(lpar.position()), impPointPlane.toGlobal(lpar.momentum()), lpar.charge(), &idealField);
210  JacobianLocalToCurvilinear jl2c(impPointPlane, lpar, idealField);
211 
212  AlgebraicSymMatrix55 mo = ROOT::Math::Similarity(jl2c.jacobian(), m);
213 
214  int ndof = 2 * hits.size() - 5;
215  chi2 = chi2 * ndof;
216  GlobalPoint vv = gp.position();
217  math::XYZPoint pos(vv.x(), vv.y(), vv.z());
218  GlobalVector pp = gp.momentum();
219  math::XYZVector mom(pp.x(), pp.y(), pp.z());
220 
221  auto track = std::make_unique<reco::Track>(chi2, ndof, pos, mom, gp.charge(), CurvilinearTrajectoryError(mo));
222 
223  // bad and edup not supported as fit not present or not reliable
224  auto tkq = recoQuality[int(q)];
225  track->setQuality(tkq);
226  // loose,tight and HP are inclusive
227  if (reco::TrackBase::highPurity == tkq) {
228  track->setQuality(reco::TrackBase::tight);
229  track->setQuality(reco::TrackBase::loose);
230  } else if (reco::TrackBase::tight == tkq) {
231  track->setQuality(reco::TrackBase::loose);
232  }
233  track->setQuality(tkq);
234  // filter???
235  tracks.emplace_back(track.release(), hits);
236  }
237  // std::cout << "processed " << nt << " good tuples " << tracks.size() << "out of " << indToEdm.size() << std::endl;
238 
239  // store tracks
240  storeTracks(iEvent, tracks, httopo);
241  iEvent.put(std::move(indToEdmP));
242 }
243 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Quality qualityByName(std::string const &name)
void storeTracks(Ev &ev, const TWH &tracksWithHits, const TrackerTopology &ttopo)
Definition: storeTracks.h:19
T z() const
Definition: PV3DBase.h:61
TrackQuality
track quality
Definition: TrackBase.h:150
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
int index() const
Definition: GeomDet.h:83
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
assert(be >=bs)
Definition: Plane.h:16
const edm::EDGetTokenT< SiPixelRecHitCollectionNew > cpuHits_
const GeomDet * det() const
const edm::EDGetTokenT< HMSstorage > hmsToken_
T x() const
Definition: PV3DBase.h:59
Eigen::Matrix< double, 5, 1 > Vector5d
Definition: FitResult.h:16
T y() const
Definition: PV3DBase.h:60
int iEvent
Definition: GenABIO.cc:224
__host__ __device__ void transformToPerigeePlane(VI5 const &ip, MI5 const &icov, VO5 &op, MO5 &ocov)
Definition: FitUtils.h:218
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > ttTopoToken_
LocalVector momentum() const
Momentum vector in the local frame.
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
double f[11][100]
bool getData(T &iHolder) const
Definition: EventSetup.h:122
std::vector< uint16_t > IndToEdm
int nt
Definition: AMPTWrapper.h:42
TrackCharge charge() const
Charge (-1, 0 or 1)
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
auto const & tracks
cannot be loose
void produce(edm::StreamID streamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
const edm::EDGetTokenT< reco::BeamSpot > tBeamSpot_
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
double b
Definition: hdecay.h:118
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ uint32_t const *__restrict__ gpuPixelDoublets::CellNeighborsVector const gpuPixelDoublets::CellTracksVector const GPUCACell::OuterHitOfCell const int32_t nHits
PixelTrackProducerFromSoA(const edm::ParameterSet &iConfig)
~PixelTrackProducerFromSoA() override=default
Eigen::Matrix< double, 5, 5 > Matrix5d
Definition: FitResult.h:20
fixed size matrix
const edm::EDGetTokenT< PixelTrackHeterogeneous > tokenTrack_
HLT enums.
std::vector< TrackWithRecHits > TracksWithRecHits
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > idealMagneticFieldToken_
pixelTrack::Quality const minQuality_
string quality
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
LocalPoint position() const
Local x and y position coordinates.
def move(src, dest)
Definition: eostools.py:511