77 const std::vector<const DetLayer*>& detLayers,
85 bool lastHitWasInvalid,
86 bool lastHitWasChanged)
const;
122 propagatorAlongToken_{
123 esConsumes<Propagator, TrackingComponentsRecord>(
iConfig.getParameter<
edm::ESInputTag>(
"propagatorAlong"))},
124 propagatorOppositeToken_{esConsumes<Propagator, TrackingComponentsRecord>(
126 mfToken_{esConsumes<MagneticField, IdealMagneticFieldRecord>()},
127 ttrhBuilderToken_{esConsumes<TransientTrackingRecHitBuilder, TransientRecHitRecord>(
129 mkFitGeomToken_{esConsumes<MkFitGeometry, TrackerRecoGeometryRecord>()},
130 putTrackCandidateToken_{produces<TrackCandidateCollection>()},
131 putSeedStopInfoToken_{produces<std::vector<SeedStopInfo>>()},
132 qualityMaxInvPt_{float(
iConfig.getParameter<
double>(
"qualityMaxInvPt"))},
133 qualityMinTheta_{float(
iConfig.getParameter<
double>(
"qualityMinTheta"))},
134 qualityMaxRsq_{float(
pow(
iConfig.getParameter<
double>(
"qualityMaxR"), 2))},
135 qualityMaxZ_{float(
iConfig.getParameter<
double>(
"qualityMaxZ"))},
136 qualityMaxPosErrSq_{float(
pow(
iConfig.getParameter<
double>(
"qualityMaxPosErr"), 2))},
137 qualitySignPt_{
iConfig.getParameter<
bool>(
"qualitySignPt")} {}
150 desc.
add(
"propagatorOpposite",
edm::ESInputTag{
"",
"PropagatorWithMaterialOpposite"});
152 desc.
add<
double>(
"qualityMaxInvPt", 100)->setComment(
"max(1/pt) for converted tracks");
153 desc.
add<
double>(
"qualityMinTheta", 0.01)->
setComment(
"lower bound on theta (or pi-theta) for converted tracks");
154 desc.
add<
double>(
"qualityMaxR", 120)->setComment(
"max(R) for the state position for converted tracks");
155 desc.
add<
double>(
"qualityMaxZ", 280)->setComment(
"max(|Z|) for the state position for converted tracks");
156 desc.
add<
double>(
"qualityMaxPosErr", 100)->setComment(
"max position error for converted tracks");
157 desc.
add<
bool>(
"qualitySignPt",
true)->setComment(
"check sign of 1/pt for converted tracks");
169 throw cms::Exception(
"LogicError") <<
"TTRHBuilder must be of type TkTransientTrackingRecHitBuilder";
184 mkFitGeom.detLayers(),
185 mkfitSeeds.seeds()));
200 const std::vector<const DetLayer*>& detLayers,
211 LogTrace(
"MkFitOutputConverter") <<
"Candidate " << candIndex <<
" pT " << cand.pT() <<
" eta " << cand.momEta()
212 <<
" phi " << cand.momPhi() <<
" chi2 " << cand.chi2();
218 (cand.state().errors.At(0, 0) + cand.state().errors.At(1, 1) + cand.state().errors.At(2, 2)) >
221 <<
"Candidate " << candIndex <<
" failed state quality checks" << cand.state().parameters;
225 auto state = cand.state();
226 state.convertFromCCSToGlbCurvilinear();
227 const auto& param =
state.parameters;
230 for (
int i = 0;
i < 5; ++
i) {
231 for (
int j =
i;
j < 5; ++
j) {
240 if (!fts.curvilinearError().posDef()) {
242 <<
"Curvilinear error not pos-def\n"
243 << fts.curvilinearError().matrix() <<
"\ncandidate " << candIndex <<
"ignored";
251 <<
"Fail pos-def check sub2.det for candidate " << candIndex <<
" with fts " << fts;
255 <<
"Fail pos-def check sub3.det for candidate " << candIndex <<
" with fts " << fts;
259 <<
"Fail pos-def check sub4.det for candidate " << candIndex <<
" with fts " << fts;
261 }
else if ((!fts.curvilinearError().matrix().Det2(det)) || det < 0) {
263 <<
"Fail pos-def check det for candidate " << candIndex <<
" with fts " << fts;
270 const int nhits = cand.nTotalHits();
271 bool lastHitInvalid =
false;
273 const auto& hitOnTrack = cand.getHitOnTrack(
i);
274 LogTrace(
"MkFitOutputConverter") <<
" hit on layer " << hitOnTrack.layer <<
" index " << hitOnTrack.index;
275 if (hitOnTrack.index < 0) {
286 const auto* detLayer = detLayers.at(hitOnTrack.layer);
287 if (detLayer ==
nullptr) {
288 throw cms::Exception(
"LogicError") <<
"DetLayer for layer index " << hitOnTrack.layer <<
" is null!";
293 lastHitInvalid =
true;
295 auto const isPixel = eventOfHits[hitOnTrack.layer].is_pix_lyr();
296 auto const& hits =
isPixel ? pixelClusterIndexToHit.
hits() : stripClusterIndexToHit.
hits();
299 if (thit.firstClusterRef().isPixel() || thit.detUnit()->type().isEndcap()) {
300 recHits.
push_back(hits[hitOnTrack.index]->clone());
302 recHits.
push_back(std::make_unique<SiStripRecHit1D>(
303 thit.localPosition(),
306 thit.firstClusterRef()));
313 lastHitInvalid =
false;
321 recHits.
sort([](
const auto&
a,
const auto&
b) {
322 const auto asub =
a.geographicalId().subdetId();
323 const auto bsub =
b.geographicalId().subdetId();
329 const auto& apos =
a.globalPosition();
330 const auto& bpos =
b.globalPosition();
333 return apos.perp2() < bpos.perp2();
341 const auto seedIndex = cand.label();
342 LogTrace(
"MkFitOutputConverter") <<
" from seed " << seedIndex <<
" seed hits";
347 :
backwardFit(fts, recHits, propagatorAlong, propagatorOpposite, hitCloner, lastHitInvalid, lastHitChanged);
348 if (!tsosDet.first.isValid()) {
350 <<
"Backward fit of candidate " << candIndex <<
" failed, ignoring the candidate";
361 seeds.
refAt(seedIndex),
375 bool lastHitWasInvalid,
376 bool lastHitWasChanged)
const {
380 for (
int i = hits.
size() - 1;
i >= 0; --
i) {
391 const auto& lastHitSurface = firstHits.front()->det()->surface();
395 if (lastHitWasInvalid || lastHitWasChanged) {
396 LogTrace(
"MkFitOutputConverter") <<
"Propagating first opposite, then along, because lastHitWasInvalid? "
397 << lastHitWasInvalid <<
" or lastHitWasChanged? " << lastHitWasChanged;
400 const auto lastHitSubdet = firstHits.front()->geographicalId().subdetId();
401 const auto& surfacePos = lastHitSurface.position();
402 const auto& lastHitPos = firstHits.front()->globalPosition();
403 bool doSwitch =
false;
405 doSwitch = (surfacePos.perp2() < lastHitPos.perp2());
407 doSwitch = (surfacePos.z() < lastHitPos.z());
411 <<
"Propagating first opposite, then along, because surface is inner than the hit; surface perp2 "
412 << surfacePos.perp() <<
" hit " << lastHitPos.perp2() <<
" surface z " << surfacePos.z() <<
" hit "
420 if (!tsosDouble.first.isValid()) {
421 LogDebug(
"MkFitOutputConverter") <<
"Propagating to startingState failed, trying in another direction next";
424 auto& startingState = tsosDouble.first;
426 if (!startingState.isValid()) {
428 <<
"startingState is not valid, FTS was\n"
429 << fts <<
" last hit surface surface:"
430 <<
"\n position " << lastHitSurface.
position() <<
"\n phiSpan " << lastHitSurface.phiSpan().first <<
","
431 << lastHitSurface.phiSpan().first <<
"\n rSpan " << lastHitSurface.rSpan().first <<
","
432 << lastHitSurface.rSpan().first <<
"\n zSpan " << lastHitSurface.zSpan().first <<
","
433 << lastHitSurface.zSpan().first;
434 return std::pair<TrajectoryStateOnSurface, const GeomDet*>();
438 startingState.rescaleError(100.);
444 &propagatorAlong, &aKFUpdator, &aChi2MeasurementEstimator, firstHits.size(),
nullptr, &hitCloner);
455 LogDebug(
"MkFitOutputConverter") <<
"using a backward fit of :" << firstHits.size() <<
" hits, starting from:\n"
456 << startingState <<
" to get the estimate of the initial state of the track.";
459 edm::LogWarning(
"MkFitOutputConverter") <<
"FitTester: first hits fit failed";
460 return std::pair<TrajectoryStateOnSurface, const GeomDet*>();
473 LogDebug(
"MkFitOutputConverter") <<
"the initial state is found to be:\n:" << firstState
474 <<
"\n it's field pointer is: " << firstState.magneticField()
475 <<
"\n the pointer from the state of the back fit was: "
478 return std::make_pair(firstState, firstMeas.
recHit()->det());
486 auto det = hits[0].det();
487 if (det ==
nullptr) {
488 throw cms::Exception(
"LogicError") <<
"Got nullptr from the first hit det()";
491 const auto& firstHitSurface = det->surface();
494 if (!tsosDouble.first.isValid()) {
495 LogDebug(
"MkFitOutputConverter") <<
"Propagating to startingState along momentum failed, trying opposite next";
499 return std::make_pair(tsosDouble.first, det);
void rescaleError(double factor)
static constexpr auto TEC
void setComment(std::string const &value)
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 bool qualitySignPt_
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_
ROOT::Math::SMatrix< double, 4, 4, ROOT::Math::MatRepSym< double, 4 > > AlgebraicSymMatrix44
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
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
ROOT::Math::SMatrix< double, 2, 2, ROOT::Math::MatRepSym< double, 2 > > AlgebraicSymMatrix22
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 float qualityMaxPosErrSq_
bool isPixel(HitType hitType)
const float qualityMinTheta_
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
const_reference at(size_type pos) const
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
Power< A, B >::type pow(const A &a, const B &b)
const float qualityMaxRsq_
Global3DVector GlobalVector
const edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > ttrhBuilderToken_
const edm::EDGetTokenT< MkFitClusterIndexToHit > stripClusterIndexToHitToken_
const float qualityMaxInvPt_