CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () 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
 
std::vector< ESProxyIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex >
const & 
esGetTokenRecordIndicesVector (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::array< std::vector< ModuleDescription const * > *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, 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
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
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 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
 
std::pair
< TrajectoryStateOnSurface,
const GeomDet * > 
convertInnermostState (const FreeTrajectoryState &fts, const edm::OwnVector< TrackingRecHit > &hits, const Propagator &propagatorAlong, const Propagator &propagatorOpposite) const
 
void produce (edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
 

Private Attributes

const edm::EDGetTokenT
< MkFitEventOfHits
eventOfHitsToken_
 
const edm::ESGetToken
< MagneticField,
IdealMagneticFieldRecord
mfToken_
 
const edm::ESGetToken
< MkFitGeometry,
TrackerRecoGeometryRecord
mkFitGeomToken_
 
const edm::EDGetTokenT
< MkFitSeedWrapper
mkfitSeedToken_
 
const edm::EDGetTokenT
< MkFitClusterIndexToHit
pixelClusterIndexToHitToken_
 
const std::string propagatorAlongName_
 
const edm::ESGetToken
< Propagator,
TrackingComponentsRecord
propagatorAlongToken_
 
const std::string propagatorOppositeName_
 
const edm::ESGetToken
< Propagator,
TrackingComponentsRecord
propagatorOppositeToken_
 
const edm::EDPutTokenT
< std::vector< SeedStopInfo > > 
putSeedStopInfoToken_
 
const edm::EDPutTokenT
< TrackCandidateCollection
putTrackCandidateToken_
 
const edm::EDGetTokenT
< edm::View< TrajectorySeed > > 
seedToken_
 
const edm::EDGetTokenT
< MkFitClusterIndexToHit
stripClusterIndexToHitToken_
 
const edm::EDGetTokenT
< MkFitOutputWrapper
tracksToken_
 
const std::string ttrhBuilderName_
 
const edm::ESGetToken
< TransientTrackingRecHitBuilder,
TransientRecHitRecord
ttrhBuilderToken_
 

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)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< B > consumes (edm::InputTag tag) noexcept
 
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<Transition Tr = Transition::Event>
constexpr auto esConsumes () noexcept
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag) noexcept
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Definition at line 58 of file MkFitOutputConverter.cc.

Constructor & Destructor Documentation

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

Definition at line 111 of file MkFitOutputConverter.cc.

References edm::ParameterSet::getParameter().

112  : eventOfHitsToken_{consumes<MkFitEventOfHits>(iConfig.getParameter<edm::InputTag>("mkFitEventOfHits"))},
113  pixelClusterIndexToHitToken_{consumes(iConfig.getParameter<edm::InputTag>("mkFitPixelHits"))},
114  stripClusterIndexToHitToken_{consumes(iConfig.getParameter<edm::InputTag>("mkFitStripHits"))},
115  mkfitSeedToken_{consumes<MkFitSeedWrapper>(iConfig.getParameter<edm::InputTag>("mkFitSeeds"))},
116  tracksToken_{consumes<MkFitOutputWrapper>(iConfig.getParameter<edm::InputTag>("tracks"))},
117  seedToken_{consumes<edm::View<TrajectorySeed>>(iConfig.getParameter<edm::InputTag>("seeds"))},
119  esConsumes<Propagator, TrackingComponentsRecord>(iConfig.getParameter<edm::ESInputTag>("propagatorAlong"))},
120  propagatorOppositeToken_{esConsumes<Propagator, TrackingComponentsRecord>(
121  iConfig.getParameter<edm::ESInputTag>("propagatorOpposite"))},
122  mfToken_{esConsumes<MagneticField, IdealMagneticFieldRecord>()},
123  ttrhBuilderToken_{esConsumes<TransientTrackingRecHitBuilder, TransientRecHitRecord>(
124  iConfig.getParameter<edm::ESInputTag>("ttrhBuilder"))},
125  mkFitGeomToken_{esConsumes<MkFitGeometry, TrackerRecoGeometryRecord>()},
126  putTrackCandidateToken_{produces<TrackCandidateCollection>()},
127  putSeedStopInfoToken_{produces<std::vector<SeedStopInfo>>()} {}
const edm::EDGetTokenT< MkFitClusterIndexToHit > pixelClusterIndexToHitToken_
const edm::ESGetToken< MkFitGeometry, TrackerRecoGeometryRecord > mkFitGeomToken_
const edm::ESGetToken< Propagator, TrackingComponentsRecord > propagatorOppositeToken_
const edm::EDGetTokenT< MkFitOutputWrapper > tracksToken_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const edm::EDPutTokenT< std::vector< SeedStopInfo > > putSeedStopInfoToken_
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > mfToken_
const edm::EDGetTokenT< edm::View< TrajectorySeed > > seedToken_
const edm::EDPutTokenT< TrackCandidateCollection > putTrackCandidateToken_
const edm::EDGetTokenT< MkFitSeedWrapper > mkfitSeedToken_
const edm::EDGetTokenT< MkFitEventOfHits > eventOfHitsToken_
const edm::ESGetToken< Propagator, TrackingComponentsRecord > propagatorAlongToken_
const edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > ttrhBuilderToken_
const edm::EDGetTokenT< MkFitClusterIndexToHit > stripClusterIndexToHitToken_
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 321 of file MkFitOutputConverter.cc.

References mps_fire::i, PixelPluginsPhase0_cfi::isBarrel, Trajectory::isValid(), Trajectory::lastMeasurement(), TrajectoryStateOnSurface::localError(), TrajectoryStateOnSurface::localParameters(), LogDebug, LogTrace, TrajectoryStateOnSurface::magneticField(), Propagator::magneticField(), oppositeToMomentum, FreeTrajectoryState::position(), Propagator::propagateWithPath(), HLT_FULL_cff::propagatorAlong, HLT_FULL_cff::propagatorOpposite, TrajectoryMeasurement::recHit(), TrajectoryStateOnSurface::rescaleError(), edm::OwnVector< T, P >::size(), TrajectoryFitter::standard, TrajectoryStateOnSurface::surface(), std::swap(), and TrajectoryMeasurement::updatedState().

Referenced by convertCandidates().

328  {
329  // First filter valid hits as in TransientInitialStateEstimator
331 
332  for (int i = hits.size() - 1; i >= 0; --i) {
333  if (hits[i].det()) {
334  // TransientTrackingRecHit::ConstRecHitContainer has shared_ptr,
335  // and it is passed to backFitter below so it is really needed
336  // to keep the interface. Since we keep the ownership in hits,
337  // let's disable the deleter.
338  firstHits.emplace_back(&(hits[i]), edm::do_nothing_deleter{});
339  }
340  }
341 
342  // Then propagate along to the surface of the last hit to get a TSOS
343  const auto& lastHitSurface = firstHits.front()->det()->surface();
344 
345  const Propagator* tryFirst = &propagatorAlong;
346  const Propagator* trySecond = &propagatorOpposite;
347  if (lastHitWasInvalid || lastHitWasChanged) {
348  LogTrace("MkFitOutputConverter") << "Propagating first opposite, then along, because lastHitWasInvalid? "
349  << lastHitWasInvalid << " or lastHitWasChanged? " << lastHitWasChanged;
350  std::swap(tryFirst, trySecond);
351  } else {
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;
356  if (isBarrel(lastHitSubdet)) {
357  doSwitch = (surfacePos.perp2() < lastHitPos.perp2());
358  } else {
359  doSwitch = (surfacePos.z() < lastHitPos.z());
360  }
361  if (doSwitch) {
362  LogTrace("MkFitOutputConverter")
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 "
365  << lastHitPos.z();
366 
367  std::swap(tryFirst, trySecond);
368  }
369  }
370 
371  auto tsosDouble = tryFirst->propagateWithPath(fts, lastHitSurface);
372  if (!tsosDouble.first.isValid()) {
373  LogDebug("MkFitOutputConverter") << "Propagating to startingState failed, trying in another direction next";
374  tsosDouble = trySecond->propagateWithPath(fts, lastHitSurface);
375  }
376  auto& startingState = tsosDouble.first;
377 
378  if (!startingState.isValid()) {
379  edm::LogWarning("MkFitOutputConverter")
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*>();
387  }
388 
389  // Then return back to the logic from TransientInitialStateEstimator
390  startingState.rescaleError(100.);
391 
392  // avoid cloning
393  KFUpdator const aKFUpdator;
394  Chi2MeasurementEstimator const aChi2MeasurementEstimator(100., 3);
395  KFTrajectoryFitter backFitter(
396  &propagatorAlong, &aKFUpdator, &aChi2MeasurementEstimator, firstHits.size(), nullptr, &hitCloner);
397 
398  // assume for now that the propagation in mkfit always alongMomentum
399  PropagationDirection backFitDirection = oppositeToMomentum;
400 
401  // only direction matters in this context
403 
404  // ignore loopers for now
405  Trajectory fitres = backFitter.fitOne(fakeSeed, firstHits, startingState, TrajectoryFitter::standard);
406 
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.";
409 
410  if (!fitres.isValid()) {
411  edm::LogWarning("MkFitOutputConverter") << "FitTester: first hits fit failed";
412  return std::pair<TrajectoryStateOnSurface, const GeomDet*>();
413  }
414 
415  TrajectoryMeasurement const& firstMeas = fitres.lastMeasurement();
416 
417  // magnetic field can be different!
418  TrajectoryStateOnSurface firstState(firstMeas.updatedState().localParameters(),
419  firstMeas.updatedState().localError(),
420  firstMeas.updatedState().surface(),
421  propagatorAlong.magneticField());
422 
423  firstState.rescaleError(100.);
424 
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: "
428  << firstMeas.updatedState().magneticField();
429 
430  return std::make_pair(firstState, firstMeas.recHit()->det());
431 }
ConstRecHitPointer const & recHit() const
const LocalTrajectoryParameters & localParameters() const
tuple propagatorAlong
size_type size() const
Definition: OwnVector.h:300
PropagationDirection
const MagneticField * magneticField() const
#define LogTrace(id)
const SurfaceType & surface() const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:150
const LocalTrajectoryError & localError() const
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Surface &) const final
Definition: Propagator.cc:10
std::vector< ConstRecHitPointer > ConstRecHitContainer
GlobalPoint position() const
bool isValid() const
Definition: Trajectory.h:257
virtual const MagneticField * magneticField() const =0
tuple propagatorOpposite
TrajectoryStateOnSurface const & updatedState() const
Log< level::Warning, false > LogWarning
#define LogDebug(id)
TrackCandidateCollection MkFitOutputConverter::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
private

Definition at line 174 of file MkFitOutputConverter.cc.

References a, funct::abs(), edm::View< T >::at(), b, edm::OwnVector< T, P >::back(), backwardFit(), HLT_FULL_cff::candidates, runTheMatrix::const, convertInnermostState(), submitPVValidationJobs::err, Exception, TrackingRecHit::geographicalId(), TrackingRecHit::globalPosition(), MkFitClusterIndexToHit::hits(), mps_fire::i, PixelPluginsPhase0_cfi::isBarrel, fastTrackerRecHitType::isPixel(), dqmiolumiharvest::j, LogTrace, PV3DBase< T, PVType, FrameType >::mag2(), SiStripPI::max, nhits, convertSQLitetoXML_cfg::output, trajectoryStateTransform::persistentState(), MkFitOutputWrapper::propagatedToFirstLayer(), edm::OwnVector< T, P >::push_back(), DetId::rawId(), HLT_FULL_cff::recHits, edm::View< T >::refAt(), edm::OwnVector< T, P >::sort(), MkFitOutputWrapper::tracks(), UNINITIALIZED, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by produce().

184  {
186  const auto& candidates = mkFitOutput.tracks();
187  output.reserve(candidates.size());
188 
189  LogTrace("MkFitOutputConverter") << "Number of candidates " << candidates.size();
190 
191  int candIndex = -1;
192  for (const auto& cand : candidates) {
193  ++candIndex;
194  LogTrace("MkFitOutputConverter") << "Candidate " << candIndex << " pT " << cand.pT() << " eta " << cand.momEta()
195  << " phi " << cand.momPhi() << " chi2 " << cand.chi2();
196 
197  // hits
199  // nTotalHits() gives sum of valid hits (nFoundHits()) and invalid/missing hits.
200  const int nhits = cand.nTotalHits();
201  bool lastHitInvalid = false;
202  for (int i = 0; i < nhits; ++i) {
203  const auto& hitOnTrack = cand.getHitOnTrack(i);
204  LogTrace("MkFitOutputConverter") << " hit on layer " << hitOnTrack.layer << " index " << hitOnTrack.index;
205  if (hitOnTrack.index < 0) {
206  // See index-desc.txt file in mkFit for description of negative values
207  //
208  // In order to use the regular InvalidTrackingRecHit I'd need
209  // a GeomDet (and "unfortunately" that is needed in
210  // TrackProducer).
211  //
212  // I guess we could take the track state and propagate it to
213  // each layer to find the actual module the track crosses, and
214  // check whether it is active or not to be able to mark
215  // inactive hits
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!";
219  }
220  // In principle an InvalidTrackingRecHitNoDet could be
221  // inserted here, but it seems that it is best to deal with
222  // them in the TrackProducer.
223  lastHitInvalid = true;
224  } else {
225  auto const isPixel = eventOfHits[hitOnTrack.layer].is_pix_lyr();
226  auto const& hits = isPixel ? pixelClusterIndexToHit.hits() : stripClusterIndexToHit.hits();
227 
228  auto const& thit = static_cast<BaseTrackerRecHit const&>(*hits[hitOnTrack.index]);
229  if (thit.firstClusterRef().isPixel() || thit.detUnit()->type().isEndcap()) {
230  recHits.push_back(hits[hitOnTrack.index]->clone());
231  } else {
232  recHits.push_back(std::make_unique<SiStripRecHit1D>(
233  thit.localPosition(),
234  LocalError(thit.localPositionError().xx(), 0.f, std::numeric_limits<float>::max()),
235  *thit.det(),
236  thit.firstClusterRef()));
237  }
238  LogTrace("MkFitOutputConverter") << " pos " << recHits.back().globalPosition().x() << " "
239  << recHits.back().globalPosition().y() << " "
240  << recHits.back().globalPosition().z() << " mag2 "
241  << recHits.back().globalPosition().mag2() << " detid "
242  << recHits.back().geographicalId().rawId() << " cluster " << hitOnTrack.index;
243  lastHitInvalid = false;
244  }
245  }
246 
247  const auto lastHitId = recHits.back().geographicalId();
248 
249  // MkFit hits are *not* in the order of propagation, sort by 3D radius for now (as we don't have loopers)
250  // TODO: Improve the sorting (extract keys? maybe even bubble sort would work well as the hits are almost in the correct order)
251  recHits.sort([](const auto& a, const auto& b) {
252  const auto asub = a.geographicalId().subdetId();
253  const auto bsub = b.geographicalId().subdetId();
254  if (asub != bsub) {
255  // Subdetector order (BPix, FPix, TIB, TID, TOB, TEC) corresponds also the navigation
256  return asub < bsub;
257  }
258 
259  const auto& apos = a.globalPosition();
260  const auto& bpos = b.globalPosition();
261 
262  if (isBarrel(asub)) {
263  return apos.perp2() < bpos.perp2();
264  }
265  return std::abs(apos.z()) < std::abs(bpos.z());
266  });
267 
268  const bool lastHitChanged = (recHits.back().geographicalId() != lastHitId); // TODO: make use of the bools
269 
270  // seed
271  const auto seedIndex = cand.label();
272  LogTrace("MkFitOutputConverter") << " from seed " << seedIndex << " seed hits";
273 
274  // state
275  auto state = cand.state(); // copy because have to modify
276  state.convertFromCCSToGlbCurvilinear();
277  const auto& param = state.parameters;
278  const auto& err = state.errors;
280  for (int i = 0; i < 5; ++i) {
281  for (int j = i; j < 5; ++j) {
282  cov[i][j] = err.At(i, j);
283  }
284  }
285 
286  auto fts = FreeTrajectoryState(
288  GlobalPoint(param[0], param[1], param[2]), GlobalVector(param[3], param[4], param[5]), state.charge, &mf),
290  if (!fts.curvilinearError().posDef()) {
291  edm::LogInfo("MkFitOutputConverter") << "Curvilinear error not pos-def\n"
292  << fts.curvilinearError().matrix() << "\ncandidate ignored";
293  continue;
294  }
295 
296  auto tsosDet =
297  mkFitOutput.propagatedToFirstLayer()
298  ? convertInnermostState(fts, recHits, propagatorAlong, propagatorOpposite)
299  : backwardFit(fts, recHits, propagatorAlong, propagatorOpposite, hitCloner, lastHitInvalid, lastHitChanged);
300  if (!tsosDet.first.isValid()) {
301  edm::LogInfo("MkFitOutputConverter")
302  << "Backward fit of candidate " << candIndex << " failed, ignoring the candidate";
303  continue;
304  }
305 
306  // convert to persistent, from CkfTrackCandidateMakerBase
307  auto pstate = trajectoryStateTransform::persistentState(tsosDet.first, tsosDet.second->geographicalId().rawId());
308 
309  output.emplace_back(
310  recHits,
311  seeds.at(seedIndex),
312  pstate,
313  seeds.refAt(seedIndex),
314  0, // mkFit does not produce loopers, so set nLoops=0
315  static_cast<uint8_t>(StopReason::UNINITIALIZED) // TODO: ignore details of stopping reason as well for now
316  );
317  }
318  return output;
319 }
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
#define LogTrace(id)
RefToBase< value_type > refAt(size_type i) const
void push_back(D *&d)
Definition: OwnVector.h:326
bool propagatedToFirstLayer() const
T z() const
Definition: PV3DBase.h:61
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Log< level::Info, false > LogInfo
void sort(S s)
Definition: OwnVector.h:502
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
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
bool isPixel(HitType hitType)
const_reference at(size_type pos) const
std::vector< TrackingRecHit const * > & hits()
DetId geographicalId() const
mkfit::TrackVec const & tracks() const
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 433 of file MkFitOutputConverter.cc.

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

Referenced by convertCandidates().

437  {
438  auto det = hits[0].det();
439  if (det == nullptr) {
440  throw cms::Exception("LogicError") << "Got nullptr from the first hit det()";
441  }
442 
443  const auto& firstHitSurface = det->surface();
444 
445  auto tsosDouble = propagatorAlong.propagateWithPath(fts, firstHitSurface);
446  if (!tsosDouble.first.isValid()) {
447  LogDebug("MkFitOutputConverter") << "Propagating to startingState along momentum failed, trying opposite next";
448  tsosDouble = propagatorOpposite.propagateWithPath(fts, firstHitSurface);
449  }
450 
451  return std::make_pair(tsosDouble.first, det);
452 }
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Surface &) const final
Definition: Propagator.cc:10
#define LogDebug(id)
void MkFitOutputConverter::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 129 of file MkFitOutputConverter.cc.

References edm::ParameterSetDescription::add(), edm::ConfigurationDescriptions::addWithDefaultLabel(), and submitPVResolutionJobs::desc.

129  {
131 
132  desc.add("mkFitEventOfHits", edm::InputTag{"mkFitEventOfHits"});
133  desc.add("mkFitPixelHits", edm::InputTag{"mkFitSiPixelHits"});
134  desc.add("mkFitStripHits", edm::InputTag{"mkFitSiStripHits"});
135  desc.add("mkFitSeeds", edm::InputTag{"mkFitSeedConverter"});
136  desc.add("tracks", edm::InputTag{"mkFitProducer"});
137  desc.add("seeds", edm::InputTag{"initialStepSeeds"});
138  desc.add("ttrhBuilder", edm::ESInputTag{"", "WithTrackAngle"});
139  desc.add("propagatorAlong", edm::ESInputTag{"", "PropagatorWithMaterial"});
140  desc.add("propagatorOpposite", edm::ESInputTag{"", "PropagatorWithMaterialOpposite"});
141 
142  descriptions.addWithDefaultLabel(desc);
143 }
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
overrideprivatevirtual

Implements edm::global::EDProducerBase.

Definition at line 145 of file MkFitOutputConverter.cc.

References runTheMatrix::const, convertCandidates(), edm::Event::emplace(), eventOfHitsToken_, Exception, edm::Event::get(), edm::EventSetup::getData(), mfToken_, mkFitGeomToken_, mkfitSeedToken_, pixelClusterIndexToHitToken_, propagatorAlongToken_, propagatorOppositeToken_, putSeedStopInfoToken_, putTrackCandidateToken_, DetachedQuadStep_cff::seeds, seedToken_, stripClusterIndexToHitToken_, tracksToken_, and ttrhBuilderToken_.

145  {
146  const auto& seeds = iEvent.get(seedToken_);
147  const auto& mkfitSeeds = iEvent.get(mkfitSeedToken_);
148 
149  const auto& ttrhBuilder = iSetup.getData(ttrhBuilderToken_);
150  const auto* tkBuilder = dynamic_cast<TkTransientTrackingRecHitBuilder const*>(&ttrhBuilder);
151  if (!tkBuilder) {
152  throw cms::Exception("LogicError") << "TTRHBuilder must be of type TkTransientTrackingRecHitBuilder";
153  }
154  const auto& mkFitGeom = iSetup.getData(mkFitGeomToken_);
155 
156  // Convert mkfit presentation back to CMSSW
159  iEvent.get(eventOfHitsToken_).get(),
162  seeds,
163  iSetup.getData(mfToken_),
166  tkBuilder->cloner(),
167  mkFitGeom.detLayers(),
168  mkfitSeeds.seeds()));
169 
170  // TODO: SeedStopInfo is currently unfilled
171  iEvent.emplace(putSeedStopInfoToken_, seeds.size());
172 }
const edm::EDGetTokenT< MkFitClusterIndexToHit > pixelClusterIndexToHitToken_
const edm::ESGetToken< Propagator, TrackingComponentsRecord > propagatorOppositeToken_
const edm::ESGetToken< MkFitGeometry, TrackerRecoGeometryRecord > mkFitGeomToken_
const edm::EDGetTokenT< MkFitOutputWrapper > tracksToken_
bool getData(T &iHolder) const
Definition: EventSetup.h:128
const edm::EDPutTokenT< std::vector< SeedStopInfo > > putSeedStopInfoToken_
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > mfToken_
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
Definition: Event.h:346
const edm::EDPutTokenT< TrackCandidateCollection > putTrackCandidateToken_
const edm::EDGetTokenT< MkFitSeedWrapper > mkfitSeedToken_
OrphanHandle< PROD > emplace(EDPutTokenT< PROD > token, Args &&...args)
puts a new product
Definition: Event.h:433
const edm::EDGetTokenT< MkFitEventOfHits > eventOfHitsToken_
const edm::ESGetToken< Propagator, TrackingComponentsRecord > propagatorAlongToken_
const edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > ttrhBuilderToken_
const edm::EDGetTokenT< MkFitClusterIndexToHit > stripClusterIndexToHitToken_

Member Data Documentation

const edm::EDGetTokenT<MkFitEventOfHits> MkFitOutputConverter::eventOfHitsToken_
private

Definition at line 93 of file MkFitOutputConverter.cc.

Referenced by produce().

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

Definition at line 101 of file MkFitOutputConverter.cc.

Referenced by produce().

const edm::ESGetToken<MkFitGeometry, TrackerRecoGeometryRecord> MkFitOutputConverter::mkFitGeomToken_
private

Definition at line 103 of file MkFitOutputConverter.cc.

Referenced by produce().

const edm::EDGetTokenT<MkFitSeedWrapper> MkFitOutputConverter::mkfitSeedToken_
private

Definition at line 96 of file MkFitOutputConverter.cc.

Referenced by produce().

const edm::EDGetTokenT<MkFitClusterIndexToHit> MkFitOutputConverter::pixelClusterIndexToHitToken_
private

Definition at line 94 of file MkFitOutputConverter.cc.

Referenced by produce().

const std::string MkFitOutputConverter::propagatorAlongName_
private

Definition at line 107 of file MkFitOutputConverter.cc.

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

Definition at line 99 of file MkFitOutputConverter.cc.

Referenced by produce().

const std::string MkFitOutputConverter::propagatorOppositeName_
private

Definition at line 108 of file MkFitOutputConverter.cc.

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

Definition at line 100 of file MkFitOutputConverter.cc.

Referenced by produce().

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

Definition at line 105 of file MkFitOutputConverter.cc.

Referenced by produce().

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

Definition at line 104 of file MkFitOutputConverter.cc.

Referenced by produce().

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

Definition at line 98 of file MkFitOutputConverter.cc.

Referenced by produce().

const edm::EDGetTokenT<MkFitClusterIndexToHit> MkFitOutputConverter::stripClusterIndexToHitToken_
private

Definition at line 95 of file MkFitOutputConverter.cc.

Referenced by produce().

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

Definition at line 97 of file MkFitOutputConverter.cc.

Referenced by produce().

const std::string MkFitOutputConverter::ttrhBuilderName_
private

Definition at line 106 of file MkFitOutputConverter.cc.

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

Definition at line 102 of file MkFitOutputConverter.cc.

Referenced by produce().