40 #include "LayerNumberConverter.h"
42 #include "mkFit/HitStructures.h"
69 const mkfit::EventOfHits& eventOfHits,
77 const std::vector<const DetLayer*>& detLayers,
85 bool lastHitWasInvalid,
86 bool lastHitWasChanged)
const;
118 propagatorAlongToken_{
119 esConsumes<Propagator, TrackingComponentsRecord>(
iConfig.getParameter<
edm::ESInputTag>(
"propagatorAlong"))},
120 propagatorOppositeToken_{esConsumes<Propagator, TrackingComponentsRecord>(
122 mfToken_{esConsumes<MagneticField, IdealMagneticFieldRecord>()},
123 ttrhBuilderToken_{esConsumes<TransientTrackingRecHitBuilder, TransientRecHitRecord>(
125 mkFitGeomToken_{esConsumes<MkFitGeometry, TrackerRecoGeometryRecord>()},
126 putTrackCandidateToken_{produces<TrackCandidateCollection>()},
127 putSeedStopInfoToken_{produces<std::vector<SeedStopInfo>>()} {}
140 desc.
add(
"propagatorOpposite",
edm::ESInputTag{
"",
"PropagatorWithMaterialOpposite"});
152 throw cms::Exception(
"LogicError") <<
"TTRHBuilder must be of type TkTransientTrackingRecHitBuilder";
167 mkFitGeom.detLayers(),
168 mkfitSeeds.seeds()));
175 const mkfit::EventOfHits& eventOfHits,
183 const std::vector<const DetLayer*>& detLayers,
194 LogTrace(
"MkFitOutputConverter") <<
"Candidate " << candIndex <<
" pT " << cand.pT() <<
" eta " << cand.momEta()
195 <<
" phi " << cand.momPhi() <<
" chi2 " << cand.chi2();
200 const int nhits = cand.nTotalHits();
201 bool lastHitInvalid =
false;
203 const auto& hitOnTrack = cand.getHitOnTrack(
i);
204 LogTrace(
"MkFitOutputConverter") <<
" hit on layer " << hitOnTrack.layer <<
" index " << hitOnTrack.index;
205 if (hitOnTrack.index < 0) {
216 const auto* detLayer = detLayers.at(hitOnTrack.layer);
217 if (detLayer ==
nullptr) {
218 throw cms::Exception(
"LogicError") <<
"DetLayer for layer index " << hitOnTrack.layer <<
" is null!";
223 lastHitInvalid =
true;
225 auto const isPixel = eventOfHits[hitOnTrack.layer].is_pix_lyr();
226 auto const& hits =
isPixel ? pixelClusterIndexToHit.
hits() : stripClusterIndexToHit.
hits();
229 if (thit.firstClusterRef().isPixel() || thit.detUnit()->type().isEndcap()) {
230 recHits.
push_back(hits[hitOnTrack.index]->clone());
232 recHits.
push_back(std::make_unique<SiStripRecHit1D>(
233 thit.localPosition(),
236 thit.firstClusterRef()));
243 lastHitInvalid =
false;
251 recHits.
sort([](
const auto&
a,
const auto&
b) {
252 const auto asub =
a.geographicalId().subdetId();
253 const auto bsub =
b.geographicalId().subdetId();
259 const auto& apos =
a.globalPosition();
260 const auto& bpos =
b.globalPosition();
263 return apos.perp2() < bpos.perp2();
271 const auto seedIndex = cand.label();
272 LogTrace(
"MkFitOutputConverter") <<
" from seed " << seedIndex <<
" seed hits";
275 auto state = cand.state();
276 state.convertFromCCSToGlbCurvilinear();
277 const auto& param =
state.parameters;
280 for (
int i = 0;
i < 5; ++
i) {
281 for (
int j =
i;
j < 5; ++
j) {
290 if (!fts.curvilinearError().posDef()) {
291 edm::LogInfo(
"MkFitOutputConverter") <<
"Curvilinear error not pos-def\n"
292 << fts.curvilinearError().matrix() <<
"\ncandidate ignored";
299 :
backwardFit(fts, recHits, propagatorAlong, propagatorOpposite, hitCloner, lastHitInvalid, lastHitChanged);
300 if (!tsosDet.first.isValid()) {
302 <<
"Backward fit of candidate " << candIndex <<
" failed, ignoring the candidate";
313 seeds.
refAt(seedIndex),
327 bool lastHitWasInvalid,
328 bool lastHitWasChanged)
const {
332 for (
int i = hits.
size() - 1;
i >= 0; --
i) {
343 const auto& lastHitSurface = firstHits.front()->det()->surface();
347 if (lastHitWasInvalid || lastHitWasChanged) {
348 LogTrace(
"MkFitOutputConverter") <<
"Propagating first opposite, then along, because lastHitWasInvalid? "
349 << lastHitWasInvalid <<
" or lastHitWasChanged? " << lastHitWasChanged;
352 const auto lastHitSubdet = firstHits.front()->geographicalId().subdetId();
353 const auto& surfacePos = lastHitSurface.position();
354 const auto& lastHitPos = firstHits.front()->globalPosition();
355 bool doSwitch =
false;
357 doSwitch = (surfacePos.perp2() < lastHitPos.perp2());
359 doSwitch = (surfacePos.z() < lastHitPos.z());
363 <<
"Propagating first opposite, then along, because surface is inner than the hit; surface perp2 "
364 << surfacePos.perp() <<
" hit " << lastHitPos.perp2() <<
" surface z " << surfacePos.z() <<
" hit "
372 if (!tsosDouble.first.isValid()) {
373 LogDebug(
"MkFitOutputConverter") <<
"Propagating to startingState failed, trying in another direction next";
376 auto& startingState = tsosDouble.first;
378 if (!startingState.isValid()) {
380 <<
"startingState is not valid, FTS was\n"
381 << fts <<
" last hit surface surface:"
382 <<
"\n position " << lastHitSurface.
position() <<
"\n phiSpan " << lastHitSurface.phiSpan().first <<
","
383 << lastHitSurface.phiSpan().first <<
"\n rSpan " << lastHitSurface.rSpan().first <<
","
384 << lastHitSurface.rSpan().first <<
"\n zSpan " << lastHitSurface.zSpan().first <<
","
385 << lastHitSurface.zSpan().first;
386 return std::pair<TrajectoryStateOnSurface, const GeomDet*>();
390 startingState.rescaleError(100.);
396 &propagatorAlong, &aKFUpdator, &aChi2MeasurementEstimator, firstHits.size(),
nullptr, &hitCloner);
407 LogDebug(
"MkFitOutputConverter") <<
"using a backward fit of :" << firstHits.size() <<
" hits, starting from:\n"
408 << startingState <<
" to get the estimate of the initial state of the track.";
411 edm::LogWarning(
"MkFitOutputConverter") <<
"FitTester: first hits fit failed";
412 return std::pair<TrajectoryStateOnSurface, const GeomDet*>();
425 LogDebug(
"MkFitOutputConverter") <<
"the initial state is found to be:\n:" << firstState
426 <<
"\n it's field pointer is: " << firstState.magneticField()
427 <<
"\n the pointer from the state of the back fit was: "
430 return std::make_pair(firstState, firstMeas.
recHit()->det());
438 auto det = hits[0].det();
439 if (det ==
nullptr) {
440 throw cms::Exception(
"LogicError") <<
"Got nullptr from the first hit det()";
443 const auto& firstHitSurface = det->surface();
446 if (!tsosDouble.first.isValid()) {
447 LogDebug(
"MkFitOutputConverter") <<
"Propagating to startingState along momentum failed, trying opposite next";
451 return std::make_pair(tsosDouble.first, det);
void rescaleError(double factor)
static constexpr auto TEC
const edm::EDGetTokenT< MkFitClusterIndexToHit > pixelClusterIndexToHitToken_
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
std::pair< TrajectoryStateOnSurface, const GeomDet * > backwardFit(const FreeTrajectoryState &fts, const edm::OwnVector< TrackingRecHit > &hits, const Propagator &propagatorAlong, const Propagator &propagatorOpposite, const TkClonerImpl &hitCloner, bool lastHitWasInvalid, bool lastHitWasChanged) const
ConstRecHitPointer const & recHit() const
const edm::ESGetToken< MkFitGeometry, TrackerRecoGeometryRecord > mkFitGeomToken_
const edm::ESGetToken< Propagator, TrackingComponentsRecord > propagatorOppositeToken_
const LocalTrajectoryParameters & localParameters() const
#define DEFINE_FWK_MODULE(type)
std::vector< TrackCandidate > TrackCandidateCollection
Global3DPoint GlobalPoint
constexpr uint32_t rawId() const
get the raw id
void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
const edm::EDGetTokenT< MkFitOutputWrapper > tracksToken_
virtual GlobalPoint globalPosition() const
const MagneticField * magneticField() const
RefToBase< value_type > refAt(size_type i) const
bool getData(T &iHolder) const
const edm::EDPutTokenT< std::vector< SeedStopInfo > > putSeedStopInfoToken_
const SurfaceType & surface() const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > mfToken_
~MkFitOutputConverter() override=default
TrajectoryMeasurement const & lastMeasurement() const
bool propagatedToFirstLayer() const
MkFitOutputConverter(edm::ParameterSet const &iConfig)
Abs< T >::type abs(const T &t)
TrackCandidateCollection convertCandidates(const MkFitOutputWrapper &mkFitOutput, const mkfit::EventOfHits &eventOfHits, const MkFitClusterIndexToHit &pixelClusterIndexToHit, const MkFitClusterIndexToHit &stripClusterIndexToHit, const edm::View< TrajectorySeed > &seeds, const MagneticField &mf, const Propagator &propagatorAlong, const Propagator &propagatorOpposite, const TkClonerImpl &hitCloner, const std::vector< const DetLayer * > &detLayers, const mkfit::TrackVec &mkFitSeeds) const
const edm::EDGetTokenT< edm::View< TrajectorySeed > > seedToken_
bool get(ProductID const &oid, Handle< PROD > &result) const
const edm::EDPutTokenT< TrackCandidateCollection > putTrackCandidateToken_
const LocalTrajectoryError & localError() const
static constexpr auto TOB
ParameterDescriptionBase * add(U const &iLabel, T const &value)
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Surface &) const final
const std::string ttrhBuilderName_
bool isEndcap(GeomDetEnumerators::SubDetector m)
const edm::EDGetTokenT< MkFitSeedWrapper > mkfitSeedToken_
std::vector< ConstRecHitPointer > ConstRecHitContainer
Log< level::Info, false > LogInfo
GlobalPoint position() const
std::vector< Track > TrackVec
static constexpr auto TIB
OrphanHandle< PROD > emplace(EDPutTokenT< PROD > token, Args &&...args)
puts a new product
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T getParameter(std::string const &) const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
virtual const MagneticField * magneticField() const =0
std::pair< TrajectoryStateOnSurface, const GeomDet * > convertInnermostState(const FreeTrajectoryState &fts, const edm::OwnVector< TrackingRecHit > &hits, const Propagator &propagatorAlong, const Propagator &propagatorOpposite) const
const edm::EDGetTokenT< MkFitEventOfHits > eventOfHitsToken_
const std::string propagatorOppositeName_
bool isPixel(HitType hitType)
const_reference at(size_type pos) const
const std::string propagatorAlongName_
TrajectoryStateOnSurface const & updatedState() const
const edm::ESGetToken< Propagator, TrackingComponentsRecord > propagatorAlongToken_
std::vector< TrackingRecHit const * > & hits()
DetId geographicalId() const
Log< level::Warning, false > LogWarning
mkfit::TrackVec const & tracks() const
static constexpr auto TID
Global3DVector GlobalVector
const edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > ttrhBuilderToken_
const edm::EDGetTokenT< MkFitClusterIndexToHit > stripClusterIndexToHitToken_