CMS 3D CMS Logo

PixelTrackProducerFromSoA.cc
Go to the documentation of this file.
23 
28 
32 
33 #include "storeTracks.h"
34 
38 
43 template <typename TrackerTraits>
47 
48 public:
49  using IndToEdm = std::vector<uint32_t>;
50 
51  explicit PixelTrackProducerFromSoAT(const edm::ParameterSet &iConfig);
52  ~PixelTrackProducerFromSoAT() override = default;
53 
54  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
55 
57 
58 private:
59  void produce(edm::StreamID streamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override;
60 
61  // Event Data tokens
66  // Event Setup tokens
69 
70  int32_t const minNumberOfHits_;
72 };
73 
74 template <typename TrackerTraits>
76  : tBeamSpot_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot"))),
77  tokenTrack_(consumes(iConfig.getParameter<edm::InputTag>("trackSrc"))),
78  cpuHits_(consumes<SiPixelRecHitCollectionNew>(iConfig.getParameter<edm::InputTag>("pixelRecHitLegacySrc"))),
79  hmsToken_(consumes<HMSstorage>(iConfig.getParameter<edm::InputTag>("pixelRecHitLegacySrc"))),
80  idealMagneticFieldToken_(esConsumes()),
81  ttTopoToken_(esConsumes()),
82  minNumberOfHits_(iConfig.getParameter<int>("minNumberOfHits")),
83  minQuality_(pixelTrack::qualityByName(iConfig.getParameter<std::string>("minQuality"))) {
85  throw cms::Exception("PixelTrackConfiguration")
86  << iConfig.getParameter<std::string>("minQuality") + " is not a pixelTrack::Quality";
87  }
89  throw cms::Exception("PixelTrackConfiguration")
90  << iConfig.getParameter<std::string>("minQuality") + " not supported";
91  }
92  produces<TrackingRecHitCollection>();
93  produces<reco::TrackExtraCollection>();
94  // TrackCollection refers to TrackingRechit and TrackExtra
95  // collections, need to declare its production after them to work
96  // around a rare race condition in framework scheduling
97  produces<reco::TrackCollection>();
98  produces<IndToEdm>();
99 }
100 
101 template <typename TrackerTraits>
104  desc.add<edm::InputTag>("beamSpot", edm::InputTag("offlineBeamSpot"));
105  desc.add<edm::InputTag>("trackSrc", edm::InputTag("pixelTracksSoA"));
106  desc.add<edm::InputTag>("pixelRecHitLegacySrc", edm::InputTag("siPixelRecHitsPreSplittingLegacy"));
107  desc.add<int>("minNumberOfHits", 0);
108  desc.add<std::string>("minQuality", "loose");
109  descriptions.addWithDefaultLabel(desc);
110 }
111 
112 template <typename TrackerTraits>
115  const edm::EventSetup &iSetup) const {
116  // enum class Quality : uint8_t { bad = 0, edup, dup, loose, strict, tight, highPurity };
125 
126  // std::cout << "Converting gpu helix in reco tracks" << std::endl;
127 
128  auto indToEdmP = std::make_unique<IndToEdm>();
129  auto &indToEdm = *indToEdmP;
130 
131  auto const &idealField = iSetup.getData(idealMagneticFieldToken_);
132 
134 
135  auto const &httopo = iSetup.getData(ttTopoToken_);
136 
137  const auto &bsh = iEvent.get(tBeamSpot_);
138  GlobalPoint bs(bsh.x0(), bsh.y0(), bsh.z0());
139 
140  auto const &rechits = iEvent.get(cpuHits_);
141  std::vector<TrackingRecHit const *> hitmap;
142  auto const &rcs = rechits.data();
143  auto nhits = rcs.size();
144 
145  hitmap.resize(nhits, nullptr);
146 
147  auto const *hitsModuleStart = iEvent.get(hmsToken_).get();
148  auto fc = hitsModuleStart;
149 
150  for (auto const &h : rcs) {
151  auto const &thit = static_cast<BaseTrackerRecHit const &>(h);
152  auto detI = thit.det()->index();
153  auto const &clus = thit.firstClusterRef();
154  assert(clus.isPixel());
155  auto i = fc[detI] + clus.pixelCluster().originalId();
156  if (i >= hitmap.size())
157  hitmap.resize(i + 256, nullptr); // only in case of hit overflow in one module
158 
159  assert(nullptr == hitmap[i]);
160  hitmap[i] = &h;
161  }
162 
163  std::vector<const TrackingRecHit *> hits;
164  hits.reserve(5);
165 
166  auto const &tsoa = iEvent.get(tokenTrack_);
167  auto const *quality = tsoa.view().quality();
168  auto const &hitIndices = tsoa.view().hitIndices();
169  auto nTracks = tsoa.view().nTracks();
170 
171  tracks.reserve(nTracks);
172 
173  int32_t nt = 0;
174 
175  //sort index by pt
176  std::vector<int32_t> sortIdxs(nTracks);
177  std::iota(sortIdxs.begin(), sortIdxs.end(), 0);
178  std::sort(sortIdxs.begin(), sortIdxs.end(), [&](int32_t const i1, int32_t const i2) {
179  return tsoa.view()[i1].pt() > tsoa.view()[i2].pt();
180  });
181 
182  //store the index of the SoA: indToEdm[index_SoAtrack] -> index_edmTrack (if it exists)
183  indToEdm.resize(sortIdxs.size(), -1);
184  for (const auto &it : sortIdxs) {
185  auto nHits = tracksHelpers::nHits(tsoa.view(), it);
186  assert(nHits >= 3);
187  auto q = quality[it];
188 
189  if (q < minQuality_)
190  continue;
191  if (nHits < minNumberOfHits_) //move to nLayers?
192  continue;
193  indToEdm[it] = nt;
194  ++nt;
195 
196  hits.resize(nHits);
197  auto b = hitIndices.begin(it);
198  for (int iHit = 0; iHit < nHits; ++iHit)
199  hits[iHit] = hitmap[*(b + iHit)];
200 
201  // mind: this values are respect the beamspot!
202 
203  float chi2 = tsoa.view()[it].chi2();
204  float phi = tracksHelpers::phi(tsoa.view(), it);
205 
206  riemannFit::Vector5d ipar, opar;
207  riemannFit::Matrix5d icov, ocov;
208  tracksHelpers::template copyToDense<riemannFit::Vector5d, riemannFit::Matrix5d>(tsoa.view(), ipar, icov, it);
209  riemannFit::transformToPerigeePlane(ipar, icov, opar, ocov);
210 
211  LocalTrajectoryParameters lpar(opar(0), opar(1), opar(2), opar(3), opar(4), 1.);
213  for (int i = 0; i < 5; ++i)
214  for (int j = i; j < 5; ++j)
215  m(i, j) = ocov(i, j);
216 
217  float sp = std::sin(phi);
218  float cp = std::cos(phi);
219  Surface::RotationType rot(sp, -cp, 0, 0, 0, -1.f, cp, sp, 0);
220 
221  Plane impPointPlane(bs, rot);
223  impPointPlane.toGlobal(lpar.position()), impPointPlane.toGlobal(lpar.momentum()), lpar.charge(), &idealField);
224  JacobianLocalToCurvilinear jl2c(impPointPlane, lpar, idealField);
225 
226  AlgebraicSymMatrix55 mo = ROOT::Math::Similarity(jl2c.jacobian(), m);
227 
228  int ndof = 2 * hits.size() - 5;
229  chi2 = chi2 * ndof;
230  GlobalPoint vv = gp.position();
231  math::XYZPoint pos(vv.x(), vv.y(), vv.z());
232  GlobalVector pp = gp.momentum();
233  math::XYZVector mom(pp.x(), pp.y(), pp.z());
234 
235  auto track = std::make_unique<reco::Track>(chi2, ndof, pos, mom, gp.charge(), CurvilinearTrajectoryError(mo));
236 
237  // bad and edup not supported as fit not present or not reliable
238  auto tkq = recoQuality[int(q)];
239  track->setQuality(tkq);
240  // loose,tight and HP are inclusive
241  if (reco::TrackBase::highPurity == tkq) {
242  track->setQuality(reco::TrackBase::tight);
243  track->setQuality(reco::TrackBase::loose);
244  } else if (reco::TrackBase::tight == tkq) {
245  track->setQuality(reco::TrackBase::loose);
246  }
247  track->setQuality(tkq);
248  // filter???
249  tracks.emplace_back(track.release(), hits);
250  }
251  // std::cout << "processed " << nt << " good tuples " << tracks.size() << "out of " << indToEdm.size() << std::endl;
252 
253  // store tracks
254  storeTracks(iEvent, tracks, httopo);
255  iEvent.put(std::move(indToEdmP));
256 }
257 
260 
263 
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
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const edm::EDGetTokenT< reco::BeamSpot > tBeamSpot_
const edm::EDGetTokenT< TrackSoAHost > tokenTrack_
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
const edm::EDGetTokenT< SiPixelRecHitCollectionNew > cpuHits_
TrackQuality
track quality
Definition: TrackBase.h:150
int index() const
Definition: GeomDet.h:83
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
~PixelTrackProducerFromSoAT() override=default
assert(be >=bs)
Definition: Plane.h:16
const GeomDet * det() const
string quality
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< MagneticField, IdealMagneticFieldRecord > idealMagneticFieldToken_
LocalVector momentum() const
Momentum vector in the local frame.
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
double f[11][100]
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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
const edm::EDGetTokenT< HMSstorage > hmsToken_
pixelTrack::Quality const minQuality_
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
void produce(edm::StreamID streamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
PixelTrackProducerFromSoAT(const edm::ParameterSet &iConfig)
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
double b
Definition: hdecay.h:120
Eigen::Matrix< double, 5, 5 > Matrix5d
Definition: FitResult.h:20
fixed size matrix
HLT enums.
std::vector< TrackWithRecHits > TracksWithRecHits
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > ttTopoToken_
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
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
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)