CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
MkFitOutputConverter Class Reference
Inheritance diagram for MkFitOutputConverter:
edm::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 MkFitOutputConverter (edm::ParameterSet const &iConfig)
 
 ~MkFitOutputConverter () override=default
 
- Public Member Functions inherited from edm::global::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const final
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

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
 
TrackCandidateCollection convertCandidates (const MkFitOutputWrapper &mkFitOutput, const MkFitHitIndexMap &hitIndexMap, const edm::View< TrajectorySeed > &seeds, const TrackerGeometry &geom, const MagneticField &mf, const Propagator &propagatorAlong, const Propagator &propagatorOpposite, const TkClonerImpl &hitCloner, const std::vector< const DetLayer * > &detLayers, const mkfit::TrackVec &mkFitSeeds) const
 
std::pair< TrajectoryStateOnSurface, const GeomDet * > convertInnermostState (const FreeTrajectoryState &fts, const edm::OwnVector< TrackingRecHit > &hits, const Propagator &propagatorAlong, const Propagator &propagatorOpposite) const
 
std::vector< const DetLayer * > createDetLayers (const mkfit::LayerNumberConverter &lnc, const GeometricSearchTracker &tracker, const TrackerTopology &ttopo) const
 
void produce (edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
 

Private Attributes

bool backwardFitInCMSSW_
 
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecordgeomToken_
 
edm::EDGetTokenT< MkFitInputWrapperhitsSeedsToken_
 
edm::ESGetToken< MagneticField, IdealMagneticFieldRecordmfToken_
 
edm::EDGetTokenT< MeasurementTrackerEventmteToken_
 
std::string propagatorAlongName_
 
edm::ESGetToken< Propagator, TrackingComponentsRecordpropagatorAlongToken_
 
std::string propagatorOppositeName_
 
edm::ESGetToken< Propagator, TrackingComponentsRecordpropagatorOppositeToken_
 
edm::EDPutTokenT< std::vector< SeedStopInfo > > putSeedStopInfoToken_
 
edm::EDPutTokenT< TrackCandidateCollectionputTrackCandidateToken_
 
edm::EDGetTokenT< edm::View< TrajectorySeed > > seedToken_
 
edm::EDGetTokenT< MkFitOutputWrappertracksToken_
 
edm::ESGetToken< TrackerTopology, TrackerTopologyRcdttopoToken_
 
std::string ttrhBuilderName_
 
edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecordttrhBuilderToken_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::ProducerBase
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 61 of file MkFitOutputConverter.cc.

Constructor & Destructor Documentation

MkFitOutputConverter::MkFitOutputConverter ( edm::ParameterSet const &  iConfig)
explicit

Definition at line 117 of file MkFitOutputConverter.cc.

References backwardFitInCMSSW_, geomToken_, edm::ParameterSet::getParameter(), mfToken_, mteToken_, propagatorAlongToken_, propagatorOppositeToken_, putSeedStopInfoToken_, putTrackCandidateToken_, seedToken_, tracksToken_, ttopoToken_, and ttrhBuilderToken_.

118  : hitsSeedsToken_{consumes<MkFitInputWrapper>(iConfig.getParameter<edm::InputTag>("hitsSeeds"))},
119  tracksToken_{consumes<MkFitOutputWrapper>(iConfig.getParameter<edm::InputTag>("tracks"))},
120  seedToken_{consumes<edm::View<TrajectorySeed>>(iConfig.getParameter<edm::InputTag>("seeds"))},
121  mteToken_{consumes<MeasurementTrackerEvent>(iConfig.getParameter<edm::InputTag>("measurementTrackerEvent"))},
122  geomToken_{esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>()},
124  esConsumes<Propagator, TrackingComponentsRecord>(iConfig.getParameter<edm::ESInputTag>("propagatorAlong"))},
125  propagatorOppositeToken_{esConsumes<Propagator, TrackingComponentsRecord>(
126  iConfig.getParameter<edm::ESInputTag>("propagatorOpposite"))},
127  ttopoToken_{esConsumes<TrackerTopology, TrackerTopologyRcd>()},
128  mfToken_{esConsumes<MagneticField, IdealMagneticFieldRecord>()},
129  ttrhBuilderToken_{esConsumes<TransientTrackingRecHitBuilder, TransientRecHitRecord>(
130  iConfig.getParameter<edm::ESInputTag>("ttrhBuilder"))},
131  putTrackCandidateToken_{produces<TrackCandidateCollection>()},
132  putSeedStopInfoToken_{produces<std::vector<SeedStopInfo>>()},
133  backwardFitInCMSSW_{iConfig.getParameter<bool>("backwardFitInCMSSW")} {}
edm::EDGetTokenT< MeasurementTrackerEvent > mteToken_
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > ttopoToken_
edm::EDGetTokenT< MkFitOutputWrapper > tracksToken_
edm::EDPutTokenT< TrackCandidateCollection > putTrackCandidateToken_
edm::ESGetToken< Propagator, TrackingComponentsRecord > propagatorAlongToken_
edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > ttrhBuilderToken_
edm::EDGetTokenT< edm::View< TrajectorySeed > > seedToken_
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
edm::EDPutTokenT< std::vector< SeedStopInfo > > putSeedStopInfoToken_
edm::EDGetTokenT< MkFitInputWrapper > hitsSeedsToken_
edm::ESGetToken< Propagator, TrackingComponentsRecord > propagatorOppositeToken_
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > mfToken_
MkFitOutputConverter::~MkFitOutputConverter ( )
overridedefault

Member Function Documentation

std::pair< TrajectoryStateOnSurface, const GeomDet * > MkFitOutputConverter::backwardFit ( const FreeTrajectoryState fts,
const edm::OwnVector< TrackingRecHit > &  hits,
const Propagator propagatorAlong,
const Propagator propagatorOpposite,
const TkClonerImpl hitCloner,
bool  lastHitWasInvalid,
bool  lastHitWasChanged 
) const
private

Definition at line 380 of file MkFitOutputConverter.cc.

References Chi2MeasurementEstimator_cfi::Chi2MeasurementEstimator, mps_fire::i, PixelPluginsPhase0_cfi::isBarrel, Trajectory::isValid(), Trajectory::lastMeasurement(), LogDebug, LogTrace, Propagator::magneticField(), oppositeToMomentum, FreeTrajectoryState::position(), Propagator::propagateWithPath(), HLT_2018_cff::propagatorAlong, HLT_2018_cff::propagatorOpposite, TrajectoryStateOnSurface::rescaleError(), edm::OwnVector< T, P >::size(), TrajectoryFitter::standard, and std::swap().

Referenced by convertCandidates().

387  {
388  // First filter valid hits as in TransientInitialStateEstimator
390 
391  for (int i = hits.size() - 1; i >= 0; --i) {
392  if (hits[i].det()) {
393  // TransientTrackingRecHit::ConstRecHitContainer has shared_ptr,
394  // and it is passed to backFitter below so it is really needed
395  // to keep the interface. Since we keep the ownership in hits,
396  // let's disable the deleter.
397  firstHits.emplace_back(&(hits[i]), edm::do_nothing_deleter{});
398  }
399  }
400 
401  // Then propagate along to the surface of the last hit to get a TSOS
402  const auto& lastHitSurface = firstHits.front()->det()->surface();
403 
404  const Propagator* tryFirst = &propagatorAlong;
405  const Propagator* trySecond = &propagatorOpposite;
406  if (lastHitWasInvalid || lastHitWasChanged) {
407  LogTrace("MkFitOutputConverter") << "Propagating first opposite, then along, because lastHitWasInvalid? "
408  << lastHitWasInvalid << " or lastHitWasChanged? " << lastHitWasChanged;
409  std::swap(tryFirst, trySecond);
410  } else {
411  const auto lastHitSubdet = firstHits.front()->geographicalId().subdetId();
412  const auto& surfacePos = lastHitSurface.position();
413  const auto& lastHitPos = firstHits.front()->globalPosition();
414  bool doSwitch = false;
415  if (isBarrel(lastHitSubdet)) {
416  doSwitch = (surfacePos.perp2() < lastHitPos.perp2());
417  } else {
418  doSwitch = (surfacePos.z() < lastHitPos.z());
419  }
420  if (doSwitch) {
421  LogTrace("MkFitOutputConverter")
422  << "Propagating first opposite, then along, because surface is inner than the hit; surface perp2 "
423  << surfacePos.perp() << " hit " << lastHitPos.perp2() << " surface z " << surfacePos.z() << " hit "
424  << lastHitPos.z();
425 
426  std::swap(tryFirst, trySecond);
427  }
428  }
429 
430  auto tsosDouble = tryFirst->propagateWithPath(fts, lastHitSurface);
431  if (!tsosDouble.first.isValid()) {
432  LogDebug("MkFitOutputConverter") << "Propagating to startingState failed, trying in another direction next";
433  tsosDouble = trySecond->propagateWithPath(fts, lastHitSurface);
434  }
435  auto& startingState = tsosDouble.first;
436 
437  if (!startingState.isValid()) {
438  edm::LogWarning("MkFitOutputConverter")
439  << "startingState is not valid, FTS was\n"
440  << fts << " last hit surface surface:"
441  << "\n position " << lastHitSurface.position() << "\n phiSpan " << lastHitSurface.phiSpan().first << ","
442  << lastHitSurface.phiSpan().first << "\n rSpan " << lastHitSurface.rSpan().first << ","
443  << lastHitSurface.rSpan().first << "\n zSpan " << lastHitSurface.zSpan().first << ","
444  << lastHitSurface.zSpan().first;
445  return std::pair<TrajectoryStateOnSurface, const GeomDet*>();
446  }
447 
448  // Then return back to the logic from TransientInitialStateEstimator
449  startingState.rescaleError(100.);
450 
451  // avoid cloning
452  KFUpdator const aKFUpdator;
453  Chi2MeasurementEstimator const aChi2MeasurementEstimator(100., 3);
454  KFTrajectoryFitter backFitter(
455  &propagatorAlong, &aKFUpdator, &aChi2MeasurementEstimator, firstHits.size(), nullptr, &hitCloner);
456 
457  // assume for now that the propagation in mkfit always alongMomentum
458  PropagationDirection backFitDirection = oppositeToMomentum;
459 
460  // only direction matters in this context
462 
463  // ignore loopers for now
464  Trajectory fitres = backFitter.fitOne(fakeSeed, firstHits, startingState, TrajectoryFitter::standard);
465 
466  LogDebug("MkFitOutputConverter") << "using a backward fit of :" << firstHits.size() << " hits, starting from:\n"
467  << startingState << " to get the estimate of the initial state of the track.";
468 
469  if (!fitres.isValid()) {
470  edm::LogWarning("MkFitOutputConverter") << "FitTester: first hits fit failed";
471  return std::pair<TrajectoryStateOnSurface, const GeomDet*>();
472  }
473 
474  TrajectoryMeasurement const& firstMeas = fitres.lastMeasurement();
475 
476  // magnetic field can be different!
477  TrajectoryStateOnSurface firstState(firstMeas.updatedState().localParameters(),
478  firstMeas.updatedState().localError(),
479  firstMeas.updatedState().surface(),
480  propagatorAlong.magneticField());
481 
482  firstState.rescaleError(100.);
483 
484  LogDebug("MkFitOutputConverter") << "the initial state is found to be:\n:" << firstState
485  << "\n it's field pointer is: " << firstState.magneticField()
486  << "\n the pointer from the state of the back fit was: "
487  << firstMeas.updatedState().magneticField();
488 
489  return std::make_pair(firstState, firstMeas.recHit()->det());
490 }
#define LogDebug(id)
size_type size() const
Definition: OwnVector.h:300
PropagationDirection
virtual const MagneticField * magneticField() const =0
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:150
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Surface &) const final
Definition: Propagator.cc:10
#define LogTrace(id)
std::vector< ConstRecHitPointer > ConstRecHitContainer
GlobalPoint position() const
bool isValid() const
Definition: Trajectory.h:257
TrackCandidateCollection MkFitOutputConverter::convertCandidates ( const MkFitOutputWrapper mkFitOutput,
const MkFitHitIndexMap hitIndexMap,
const edm::View< TrajectorySeed > &  seeds,
const TrackerGeometry geom,
const MagneticField mf,
const Propagator propagatorAlong,
const Propagator propagatorOpposite,
const TkClonerImpl hitCloner,
const std::vector< const DetLayer * > &  detLayers,
const mkfit::TrackVec mkFitSeeds 
) const
private

Definition at line 222 of file MkFitOutputConverter.cc.

References a, funct::abs(), edm::View< T >::at(), b, edm::OwnVector< T, P >::back(), backwardFit(), backwardFitInCMSSW_, HLT_2018_cff::candidates, MkFitOutputWrapper::candidateTracks(), TrackingRecHit::clone(), MkFitHitIndexMap::clusterIndex(), convertInnermostState(), runTheMatrix::err, Exception, MkFitOutputWrapper::fitTracks(), TrackingRecHit::geographicalId(), TrackingRecHit::globalPosition(), MkFitHitIndexMap::hitPtr(), mps_fire::i, MkFitHitIndexMap::MkFitHit::index(), PixelPluginsPhase0_cfi::isBarrel, dqmiolumiharvest::j, LogTrace, PV3DBase< T, PVType, FrameType >::mag2(), nhits, convertSQLitetoXML_cfg::output, trajectoryStateTransform::persistentState(), edm::OwnVector< T, P >::push_back(), DetId::rawId(), FastTrackerRecHitMaskProducer_cfi::recHits, edm::View< T >::refAt(), edm::OwnVector< T, P >::sort(), UNINITIALIZED, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by produce().

231  {
233  const auto& candidates = backwardFitInCMSSW_ ? mkFitOutput.candidateTracks() : mkFitOutput.fitTracks();
234  output.reserve(candidates.size());
235 
236  LogTrace("MkFitOutputConverter") << "Number of candidates " << mkFitOutput.candidateTracks().size();
237 
238  int candIndex = -1;
239  for (const auto& cand : candidates) {
240  ++candIndex;
241  LogTrace("MkFitOutputConverter") << "Candidate " << candIndex << " pT " << cand.pT() << " eta " << cand.momEta()
242  << " phi " << cand.momPhi() << " chi2 " << cand.chi2();
243 
244  // hits
246  // nTotalHits() gives sum of valid hits (nFoundHits()) and
247  // invalid/missing hits (up to a maximum of 32 inside mkFit,
248  // restriction to be lifted in the future)
249  const int nhits = cand.nTotalHits();
250  bool lastHitInvalid = false;
251  for (int i = 0; i < nhits; ++i) {
252  const auto& hitOnTrack = cand.getHitOnTrack(i);
253  LogTrace("MkFitOutputConverter") << " hit on layer " << hitOnTrack.layer << " index " << hitOnTrack.index;
254  if (hitOnTrack.index < 0) {
255  // See index-desc.txt file in mkFit for description of negative values
256  //
257  // In order to use the regular InvalidTrackingRecHit I'd need
258  // a GeomDet (and "unfortunately" that is needed in
259  // TrackProducer).
260  //
261  // I guess we could take the track state and propagate it to
262  // each layer to find the actual module the track crosses, and
263  // check whether it is active or not to be able to mark
264  // inactive hits
265  const auto* detLayer = detLayers.at(hitOnTrack.layer);
266  if (detLayer == nullptr) {
267  throw cms::Exception("LogicError") << "DetLayer for layer index " << hitOnTrack.layer << " is null!";
268  }
269  // In principle an InvalidTrackingRecHitNoDet could be
270  // inserted here, but it seems that it is best to deal with
271  // them in the TrackProducer.
272  lastHitInvalid = true;
273  } else {
274  recHits.push_back(hitIndexMap.hitPtr(MkFitHitIndexMap::MkFitHit{hitOnTrack.index, hitOnTrack.layer})->clone());
275  LogTrace("MkFitOutputConverter") << " pos " << recHits.back().globalPosition().x() << " "
276  << recHits.back().globalPosition().y() << " "
277  << recHits.back().globalPosition().z() << " mag2 "
278  << recHits.back().globalPosition().mag2() << " detid "
279  << recHits.back().geographicalId().rawId() << " cluster "
280  << hitIndexMap.clusterIndex(
281  MkFitHitIndexMap::MkFitHit{hitOnTrack.index, hitOnTrack.layer});
282  lastHitInvalid = false;
283  }
284  }
285 
286  const auto lastHitId = recHits.back().geographicalId();
287 
288  // MkFit hits are *not* in the order of propagation, sort by 3D radius for now (as we don't have loopers)
289  // TODO: Improve the sorting (extract keys? maybe even bubble sort would work well as the hits are almost in the correct order)
290  recHits.sort([](const auto& a, const auto& b) {
291  const auto asub = a.geographicalId().subdetId();
292  const auto bsub = b.geographicalId().subdetId();
293  if (asub != bsub) {
294  // Subdetector order (BPix, FPix, TIB, TID, TOB, TEC) corresponds also the navigation
295  return asub < bsub;
296  }
297 
298  const auto& apos = a.globalPosition();
299  const auto& bpos = b.globalPosition();
300 
301  if (isBarrel(asub)) {
302  return apos.perp2() < bpos.perp2();
303  }
304  return std::abs(apos.z()) < std::abs(bpos.z());
305  });
306 
307  const bool lastHitChanged = (recHits.back().geographicalId() != lastHitId); // TODO: make use of the bools
308 
309  // seed
310  const auto seedIndex = cand.label();
311  LogTrace("MkFitOutputConverter") << " from seed " << seedIndex << " seed hits";
312  const auto& mkseed = mkFitSeeds.at(cand.label());
313  for (int i = 0; i < mkseed.nTotalHits(); ++i) {
314  const auto& hitOnTrack = mkseed.getHitOnTrack(i);
315  LogTrace("MkFitOutputConverter") << " hit on layer " << hitOnTrack.layer << " index " << hitOnTrack.index;
316  // sanity check for now
317  const auto& candHitOnTrack = cand.getHitOnTrack(i);
318  if (hitOnTrack.layer != candHitOnTrack.layer) {
319  throw cms::Exception("LogicError")
320  << "Candidate " << candIndex << " from seed " << seedIndex << " hit " << i
321  << " has different layer in candidate (" << candHitOnTrack.layer << ") and seed (" << hitOnTrack.layer
322  << ")."
323  << " Hit indices are " << candHitOnTrack.index << " and " << hitOnTrack.index << ", respectively";
324  }
325  if (hitOnTrack.index != candHitOnTrack.index) {
326  throw cms::Exception("LogicError") << "Candidate " << candIndex << " from seed " << seedIndex << " hit " << i
327  << " has different hit index in candidate (" << candHitOnTrack.index
328  << ") and seed (" << hitOnTrack.index << ") on layer " << hitOnTrack.layer;
329  }
330  }
331 
332  // state
333  auto state = cand.state(); // copy because have to modify
334  state.convertFromCCSToCartesian();
335  const auto& param = state.parameters;
336  const auto& err = state.errors;
338  for (int i = 0; i < 6; ++i) {
339  for (int j = i; j < 6; ++j) {
340  cov[i][j] = err.At(i, j);
341  }
342  }
343 
344  auto fts = FreeTrajectoryState(
346  GlobalPoint(param[0], param[1], param[2]), GlobalVector(param[3], param[4], param[5]), state.charge, &mf),
348  if (!fts.curvilinearError().posDef()) {
349  edm::LogWarning("MkFitOutputConverter") << "Curvilinear error not pos-def\n"
350  << fts.curvilinearError().matrix() << "\noriginal 6x6 covariance matrix\n"
351  << cov << "\ncandidate ignored";
352  continue;
353  }
354 
355  auto tsosDet =
357  ? backwardFit(fts, recHits, propagatorAlong, propagatorOpposite, hitCloner, lastHitInvalid, lastHitChanged)
358  : convertInnermostState(fts, recHits, propagatorAlong, propagatorOpposite);
359  if (!tsosDet.first.isValid()) {
360  edm::LogWarning("MkFitOutputConverter")
361  << "Backward fit of candidate " << candIndex << " failed, ignoring the candidate";
362  continue;
363  }
364 
365  // convert to persistent, from CkfTrackCandidateMakerBase
366  auto pstate = trajectoryStateTransform::persistentState(tsosDet.first, tsosDet.second->geographicalId().rawId());
367 
368  output.emplace_back(
369  recHits,
370  seeds.at(seedIndex),
371  pstate,
372  seeds.refAt(seedIndex),
373  0, // mkFit does not produce loopers, so set nLoops=0
374  static_cast<uint8_t>(StopReason::UNINITIALIZED) // TODO: ignore details of stopping reason as well for now
375  );
376  }
377  return output;
378 }
T mag2() const
Definition: PV3DBase.h:63
reference back()
Definition: OwnVector.h:431
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
std::vector< TrackCandidate > TrackCandidateCollection
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
T y() const
Definition: PV3DBase.h:60
virtual GlobalPoint globalPosition() const
mkfit::TrackVec const & fitTracks() const
RefToBase< value_type > refAt(size_type i) const
void push_back(D *&d)
Definition: OwnVector.h:326
size_t clusterIndex(MkFitHit hit) const
Get CMSSW cluster index (currently used only for debugging)
T z() const
Definition: PV3DBase.h:61
virtual TrackingRecHit * clone() const =0
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define LogTrace(id)
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
void sort(S s)
Definition: OwnVector.h:502
mkfit::TrackVec const & candidateTracks() const
double b
Definition: hdecay.h:118
std::pair< TrajectoryStateOnSurface, const GeomDet * > convertInnermostState(const FreeTrajectoryState &fts, const edm::OwnVector< TrackingRecHit > &hits, const Propagator &propagatorAlong, const Propagator &propagatorOpposite) const
double a
Definition: hdecay.h:119
const_reference at(size_type pos) const
DetId geographicalId() const
const TrackingRecHit * hitPtr(MkFitHit hit) const
Get CMSSW hit pointer.
T x() const
Definition: PV3DBase.h:59
Global3DVector GlobalVector
Definition: GlobalVector.h:10
std::pair< TrajectoryStateOnSurface, const GeomDet * > MkFitOutputConverter::convertInnermostState ( const FreeTrajectoryState fts,
const edm::OwnVector< TrackingRecHit > &  hits,
const Propagator propagatorAlong,
const Propagator propagatorOpposite 
) const
private

Definition at line 492 of file MkFitOutputConverter.cc.

References DEFINE_FWK_MODULE, Exception, LogDebug, and Propagator::propagateWithPath().

Referenced by convertCandidates().

496  {
497  auto det = hits[0].det();
498  if (det == nullptr) {
499  throw cms::Exception("LogicError") << "Got nullptr from the first hit det()";
500  }
501 
502  const auto& firstHitSurface = det->surface();
503 
504  auto tsosDouble = propagatorAlong.propagateWithPath(fts, firstHitSurface);
505  if (!tsosDouble.first.isValid()) {
506  LogDebug("MkFitOutputConverter") << "Propagating to startingState along momentum failed, trying opposite next";
507  tsosDouble = propagatorOpposite.propagateWithPath(fts, firstHitSurface);
508  }
509 
510  return std::make_pair(tsosDouble.first, det);
511 }
#define LogDebug(id)
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Surface &) const final
Definition: Propagator.cc:10
std::vector< const DetLayer * > MkFitOutputConverter::createDetLayers ( const mkfit::LayerNumberConverter &  lnc,
const GeometricSearchTracker tracker,
const TrackerTopology ttopo 
) const
private

Definition at line 181 of file MkFitOutputConverter.cc.

References GeometricSearchTracker::allLayers(), AlCaHLTBitMon_QueryRunRegistry::comp, constexpr, Exception, TrackerTopology::layer(), or, PosEndcap, TrackerTopology::side(), StripSubdetector::TEC, StripSubdetector::TIB, StripSubdetector::TID, StripSubdetector::TOB, and UNLIKELY.

Referenced by produce().

183  {
184  std::vector<const DetLayer*> dets(lnc.nLayers(), nullptr);
185 
186  auto isPlusSide = [&ttopo](const DetId& detid) {
187  return ttopo.side(detid) == static_cast<unsigned>(TrackerDetSide::PosEndcap);
188  };
189  auto setDet = [&lnc, &dets, &isPlusSide](
190  const int subdet, const int layer, const int isStereo, const DetId& detId, const DetLayer* lay) {
191  const int index = lnc.convertLayerNumber(subdet, layer, false, isStereo, isPlusSide(detId));
192  if (index < 0 or static_cast<unsigned>(index) >= dets.size()) {
193  throw cms::Exception("LogicError") << "Invalid mkFit layer index " << index << " for DetId " << detId
194  << " subdet " << subdet << " layer " << layer << " isStereo " << isStereo;
195  }
196  dets[index] = lay;
197  };
198  constexpr int monoLayer = 0;
199  constexpr int stereoLayer = 1;
200  for (const DetLayer* lay : tracker.allLayers()) {
201  const auto& comp = lay->basicComponents();
202  if (UNLIKELY(comp.empty())) {
203  throw cms::Exception("LogicError") << "Got a tracker layer (subdet " << lay->subDetector()
204  << ") with empty basicComponents.";
205  }
206  // First component is enough for layer and side information
207  const auto& detId = comp.front()->geographicalId();
208  const auto subdet = detId.subdetId();
209  const auto layer = ttopo.layer(detId);
210 
211  // TODO: mono/stereo structure is still hardcoded for phase0/1 strip tracker
212  setDet(subdet, layer, monoLayer, detId, lay);
213  if (((subdet == StripSubdetector::TIB or subdet == StripSubdetector::TOB) and (layer == 1 or layer == 2)) or
214  subdet == StripSubdetector::TID or subdet == StripSubdetector::TEC) {
215  setDet(subdet, layer, stereoLayer, detId, lay);
216  }
217  }
218 
219  return dets;
220 }
static constexpr auto TEC
std::vector< DetLayer const * > const & allLayers() const
unsigned int side(const DetId &id) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
static constexpr auto TOB
Definition: DetId.h:17
static constexpr auto TIB
unsigned int layer(const DetId &id) const
#define UNLIKELY(x)
Definition: Likely.h:21
static constexpr auto TID
#define constexpr
void MkFitOutputConverter::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 135 of file MkFitOutputConverter.cc.

References edm::ParameterSetDescription::add(), edm::ConfigurationDescriptions::addWithDefaultLabel(), and edm::ParameterDescriptionNode::setComment().

135  {
137 
138  desc.add("hitsSeeds", edm::InputTag{"mkFitInputConverter"});
139  desc.add("tracks", edm::InputTag{"mkFitProducer"});
140  desc.add("seeds", edm::InputTag{"initialStepSeeds"});
141  desc.add("measurementTrackerEvent", edm::InputTag{"MeasurementTrackerEvent"});
142  desc.add("ttrhBuilder", edm::ESInputTag{"", "WithTrackAngle"});
143  desc.add("propagatorAlong", edm::ESInputTag{"", "PropagatorWithMaterial"});
144  desc.add("propagatorOpposite", edm::ESInputTag{"", "PropagatorWithMaterialOpposite"});
145  desc.add("backwardFitInCMSSW", false)
146  ->setComment("Do backward fit (to innermost hit) in CMSSW (true) or mkFit (false)");
147 
148  descriptions.addWithDefaultLabel(desc);
149 }
void setComment(std::string const &value)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void MkFitOutputConverter::produce ( edm::StreamID  iID,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
overrideprivate

Definition at line 151 of file MkFitOutputConverter.cc.

References watchdog::const, convertCandidates(), createDetLayers(), edm::Event::emplace(), Exception, geomToken_, edm::Event::get(), edm::EventSetup::getData(), hitsSeedsToken_, mfToken_, mteToken_, propagatorAlongToken_, propagatorOppositeToken_, putSeedStopInfoToken_, putTrackCandidateToken_, seedToken_, tracksToken_, ttopoToken_, and ttrhBuilderToken_.

151  {
152  const auto& seeds = iEvent.get(seedToken_);
153  const auto& hitsSeeds = iEvent.get(hitsSeedsToken_);
154  const auto& mte = iEvent.get(mteToken_);
155 
156  const auto& ttrhBuilder = iSetup.getData(ttrhBuilderToken_);
157  const auto* tkBuilder = dynamic_cast<TkTransientTrackingRecHitBuilder const*>(&ttrhBuilder);
158  if (!tkBuilder) {
159  throw cms::Exception("LogicError") << "TTRHBuilder must be of type TkTransientTrackingRecHitBuilder";
160  }
161 
162  // Convert mkfit presentation back to CMSSW
163  const auto detlayers =
164  createDetLayers(hitsSeeds.layerNumberConverter(), *(mte.geometricSearchTracker()), iSetup.getData(ttopoToken_));
167  hitsSeeds.hitIndexMap(),
168  seeds,
169  iSetup.getData(geomToken_),
170  iSetup.getData(mfToken_),
173  tkBuilder->cloner(),
174  detlayers,
175  hitsSeeds.seeds()));
176 
177  // TODO: SeedStopInfo is currently unfilled
178  iEvent.emplace(putSeedStopInfoToken_, seeds.size());
179 }
TrackCandidateCollection convertCandidates(const MkFitOutputWrapper &mkFitOutput, const MkFitHitIndexMap &hitIndexMap, const edm::View< TrajectorySeed > &seeds, const TrackerGeometry &geom, const MagneticField &mf, const Propagator &propagatorAlong, const Propagator &propagatorOpposite, const TkClonerImpl &hitCloner, const std::vector< const DetLayer * > &detLayers, const mkfit::TrackVec &mkFitSeeds) const
edm::EDGetTokenT< MeasurementTrackerEvent > mteToken_
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > ttopoToken_
edm::EDGetTokenT< MkFitOutputWrapper > tracksToken_
bool getData(T &iHolder) const
Definition: EventSetup.h:113
edm::EDPutTokenT< TrackCandidateCollection > putTrackCandidateToken_
std::vector< const DetLayer * > createDetLayers(const mkfit::LayerNumberConverter &lnc, const GeometricSearchTracker &tracker, const TrackerTopology &ttopo) const
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:334
edm::ESGetToken< Propagator, TrackingComponentsRecord > propagatorAlongToken_
edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > ttrhBuilderToken_
edm::EDGetTokenT< edm::View< TrajectorySeed > > seedToken_
OrphanHandle< PROD > emplace(EDPutTokenT< PROD > token, Args &&...args)
puts a new product
Definition: Event.h:421
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
edm::EDPutTokenT< std::vector< SeedStopInfo > > putSeedStopInfoToken_
edm::EDGetTokenT< MkFitInputWrapper > hitsSeedsToken_
edm::ESGetToken< Propagator, TrackingComponentsRecord > propagatorOppositeToken_
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > mfToken_

Member Data Documentation

bool MkFitOutputConverter::backwardFitInCMSSW_
private

Definition at line 114 of file MkFitOutputConverter.cc.

Referenced by convertCandidates(), and MkFitOutputConverter().

edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> MkFitOutputConverter::geomToken_
private

Definition at line 103 of file MkFitOutputConverter.cc.

Referenced by MkFitOutputConverter(), and produce().

edm::EDGetTokenT<MkFitInputWrapper> MkFitOutputConverter::hitsSeedsToken_
private

Definition at line 99 of file MkFitOutputConverter.cc.

Referenced by produce().

edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> MkFitOutputConverter::mfToken_
private

Definition at line 107 of file MkFitOutputConverter.cc.

Referenced by MkFitOutputConverter(), and produce().

edm::EDGetTokenT<MeasurementTrackerEvent> MkFitOutputConverter::mteToken_
private

Definition at line 102 of file MkFitOutputConverter.cc.

Referenced by MkFitOutputConverter(), and produce().

std::string MkFitOutputConverter::propagatorAlongName_
private

Definition at line 112 of file MkFitOutputConverter.cc.

edm::ESGetToken<Propagator, TrackingComponentsRecord> MkFitOutputConverter::propagatorAlongToken_
private

Definition at line 104 of file MkFitOutputConverter.cc.

Referenced by MkFitOutputConverter(), and produce().

std::string MkFitOutputConverter::propagatorOppositeName_
private

Definition at line 113 of file MkFitOutputConverter.cc.

edm::ESGetToken<Propagator, TrackingComponentsRecord> MkFitOutputConverter::propagatorOppositeToken_
private

Definition at line 105 of file MkFitOutputConverter.cc.

Referenced by MkFitOutputConverter(), and produce().

edm::EDPutTokenT<std::vector<SeedStopInfo> > MkFitOutputConverter::putSeedStopInfoToken_
private

Definition at line 110 of file MkFitOutputConverter.cc.

Referenced by MkFitOutputConverter(), and produce().

edm::EDPutTokenT<TrackCandidateCollection> MkFitOutputConverter::putTrackCandidateToken_
private

Definition at line 109 of file MkFitOutputConverter.cc.

Referenced by MkFitOutputConverter(), and produce().

edm::EDGetTokenT<edm::View<TrajectorySeed> > MkFitOutputConverter::seedToken_
private

Definition at line 101 of file MkFitOutputConverter.cc.

Referenced by MkFitOutputConverter(), and produce().

edm::EDGetTokenT<MkFitOutputWrapper> MkFitOutputConverter::tracksToken_
private

Definition at line 100 of file MkFitOutputConverter.cc.

Referenced by MkFitOutputConverter(), and produce().

edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> MkFitOutputConverter::ttopoToken_
private

Definition at line 106 of file MkFitOutputConverter.cc.

Referenced by MkFitOutputConverter(), and produce().

std::string MkFitOutputConverter::ttrhBuilderName_
private

Definition at line 111 of file MkFitOutputConverter.cc.

edm::ESGetToken<TransientTrackingRecHitBuilder, TransientRecHitRecord> MkFitOutputConverter::ttrhBuilderToken_
private

Definition at line 108 of file MkFitOutputConverter.cc.

Referenced by MkFitOutputConverter(), and produce().