51 uint16_t detid =
id.
det();
53 std::vector<const TrackingRecHit*> hits;
58 uint16_t subdet =
id.subdetId();
65 std::vector<const TrackingRecHit*> seg2D = hit.
recHits();
67 for (std::vector<const TrackingRecHit*>::const_iterator it = seg2D.begin(); it != seg2D.end(); ++it) {
68 std::vector<const TrackingRecHit*> hits1D = (*it)->recHits();
69 copy(hits1D.begin(), hits1D.end(), back_inserter(hits));
103 auto smootherName = parameterSet.
getParameter<
string>(
"Smoother");
123 theUpdatorAtVtx = std::make_unique<MuonUpdatorAtVertex>(updatorPar, service);
136 bool reallyDoSmoothing) {
137 std::vector<bool> dummyVecBool;
138 return loadTracks(trajectories, event, dummyVecBool, ttopo, instance, reallyDoSmoothing);
143 std::vector<bool>& tkBoolVec,
146 bool reallyDoSmoothing) {
149 const string metname =
"Muon|RecoMuon|MuonTrackLoader";
157 auto updatedAtVtxTrackCollection = std::make_unique<reco::TrackCollection>();
161 trackUpdatedCollectionRefProd =
event.getRefBeforePut<
reco::TrackCollection>(instance +
"UpdatedAtVtx");
164 auto trackToTrackmap = std::make_unique<reco::TrackToTrackMap>(trackCollectionRefProd, trackUpdatedCollectionRefProd);
167 auto trackExtraCollection = std::make_unique<reco::TrackExtraCollection>();
172 auto recHitCollection = std::make_unique<TrackingRecHitCollection>();
177 auto trajectoryCollection = std::make_unique<vector<Trajectory>>();
180 if (trajectories.empty()) {
181 event.put(
std::move(recHitCollection), instance);
182 event.put(
std::move(trackExtraCollection), instance);
184 event.put(
std::move(trajectoryCollection), instance);
187 auto trajTrackMap = std::make_unique<TrajTrackAssociationCollection>();
188 event.put(
std::move(trajTrackMap), instance);
192 event.put(
std::move(updatedAtVtxTrackCollection), instance +
"UpdatedAtVtx");
200 LogTrace(metname) <<
"Create the collection of Tracks";
209 std::map<unsigned int, unsigned int> tjTkMap;
220 unsigned int tjCnt = 0;
221 for (TrajectoryContainer::iterator itRawTrajectory = trajectories.begin(); itRawTrajectory != trajectories.end();
222 ++itRawTrajectory, ++tjCnt) {
223 auto rawTrajectory =
std::move(*itRawTrajectory);
227 vector<Trajectory> trajectoriesSM =
theSmoother->trajectories(*rawTrajectory);
229 if (!trajectoriesSM.empty()) {
231 trajectory = trajectoriesSM.front();
235 LogInfo(metname) <<
"The trajectory has not been smoothed!" << endl;
239 trajectoryCollection->
push_back(trajectory);
245 pair<bool, reco::Track> resultOfTrackExtrapAtPCA =
buildTrackAtPCA(trajectory, *beamSpot);
248 if (!resultOfTrackExtrapAtPCA.first) {
265 pair<bool, reco::Track> updateResult(
false,
reco::Track());
271 if (!updateResult.first)
275 updateResult.second.setExtra(trackExtraRef);
278 trackToTrackmap->insert(
reco::TrackRef(trackCollectionRefProd, trackIndex++),
279 reco::TrackRef(trackUpdatedCollectionRefProd, trackUpdatedIndex++));
287 auto ih = recHitCollection->size();
288 t2t(trajectory, *recHitCollection, trajParams, chi2s);
289 auto ie = recHitCollection->size();
291 trackExtra.
setHits(recHitCollectionRefProd, ih, ie - ih);
296 for (; ih < ie; ++ih) {
297 auto const&
hit = (*recHitCollection)[ih];
299 for (
auto hh : hits) {
305 for (
auto hh : hits) {
306 if UNLIKELY (!updateResult.second.appendHitPattern(*
hh, ttopo))
313 trackExtraCollection->push_back(trackExtra);
318 LogTrace(metname) <<
"Debug Track being loaded pt " << track.
pt();
321 updatedAtVtxTrackCollection->push_back(updateResult.second);
323 if (tkBoolVec.size() > tjCnt)
324 tkBoolVec[tjCnt] =
true;
326 tjTkMap[iTjRef - 1] = iTkRef - 1;
330 LogTrace(metname) <<
"put the Collections in the event";
331 event.put(
std::move(recHitCollection), instance);
332 event.put(
std::move(trackExtraCollection), instance);
339 returnTrackHandle =
event.put(
std::move(updatedAtVtxTrackCollection), instance +
"UpdatedAtVtx");
342 nonUpdatedHandle = returnTrackHandle;
349 auto trajTrackMap = std::make_unique<TrajTrackAssociationCollection>(rTrajs, nonUpdatedHandle);
352 for (std::map<unsigned int, unsigned int>::iterator
i = tjTkMap.begin();
i != tjTkMap.end();
i++) {
353 trajTrackMap->insert(
edm::Ref<std::vector<Trajectory>>(rTrajs, (*i).first),
356 event.put(
std::move(trajTrackMap), instance);
359 return returnTrackHandle;
365 const string metname =
"Muon|RecoMuon|MuonTrackLoader";
368 auto trackLinksCollection = std::make_unique<reco::MuonTrackLinksCollection>();
371 if (muonCands.empty()) {
372 auto trackExtraCollection = std::make_unique<reco::TrackExtraCollection>();
373 auto recHitCollection = std::make_unique<TrackingRecHitCollection>();
377 event.put(
std::move(trackExtraCollection));
387 return event.put(
std::move(trackLinksCollection));
393 for (CandidateContainer::iterator it = muonCands.begin(); it != muonCands.end(); ++it) {
394 LogDebug(metname) <<
"Loader glbSeedRef " << (*it)->trajectory()->seedRef().isNonnull();
395 if ((*it)->trackerTrajectory())
397 <<
"tkSeedRef " << (*it)->trackerTrajectory()->seedRef().isNonnull();
399 combinedTrajs.push_back((*it)->releaseTrajectory());
401 auto tt = (*it)->releaseTrackerTrajectory();
416 LogTrace(metname) <<
"Build combinedTracks";
417 std::vector<bool> combTksVec(combinedTrajs.size(),
false);
421 std::vector<bool> trackerTksVec(trackerTrajs.size(),
false);
423 LogTrace(metname) <<
"Build trackerTracks: " << trackerTrajs.size();
427 trackerTrajs.clear();
429 LogTrace(metname) <<
"Set the final links in the MuonTrackLinks collection";
431 unsigned int candposition(0),
position(0), tkposition(0);
435 for (CandidateContainer::const_iterator it = muonCands.begin(); it != muonCands.end(); ++it, ++candposition) {
441 if (combTksVec[candposition]) {
456 trackLinksCollection->push_back(links);
466 LogWarning(metname) <<
"The MuonTrackLinkCollection is incomplete";
469 LogTrace(metname) <<
"put the MuonCollection in the event"
472 return event.put(
std::move(trackLinksCollection));
476 TrajectoryContainer& trajectories,
478 const std::vector<std::pair<Trajectory*, reco::TrackRef>>& miniMap,
481 const string& instance,
482 bool reallyDoSmoothing) {
485 const string metname =
"Muon|RecoMuon|MuonTrackLoader|TevMuonTrackLoader";
495 auto trackToTrackmap = std::make_unique<reco::TrackToTrackMap>(trackHandle, trackCollectionRefProd);
498 auto trackExtraCollection = std::make_unique<reco::TrackExtraCollection>();
503 auto recHitCollection = std::make_unique<TrackingRecHitCollection>();
508 auto trajectoryCollection = std::make_unique<std::vector<Trajectory>>();
511 if (trajectories.empty()) {
512 event.put(
std::move(recHitCollection), instance);
513 event.put(
std::move(trackExtraCollection), instance);
515 event.put(
std::move(trajectoryCollection), instance);
518 auto trajTrackMap = std::make_unique<TrajTrackAssociationCollection>();
519 event.put(
std::move(trajTrackMap), instance);
521 event.put(
std::move(trackToTrackmap), instance);
525 LogTrace(metname) <<
"Create the collection of Tracks";
536 std::map<unsigned int, unsigned int> tjTkMap;
547 for (TrajectoryContainer::iterator itRawTrajectory = trajectories.begin(); itRawTrajectory != trajectories.end();
549 auto rawTrajectory =
std::move(*itRawTrajectory);
551 std::vector<std::pair<Trajectory*, reco::TrackRef>>::const_iterator mmit;
552 for (mmit = miniMap.begin(); mmit != miniMap.end(); ++mmit) {
553 if (mmit->first == rawTrajectory.get())
554 glbRef = mmit->second;
560 vector<Trajectory> trajectoriesSM =
theSmoother->trajectories(*rawTrajectory);
562 if (!trajectoriesSM.empty()) {
564 trajectory = trajectoriesSM.front();
567 LogInfo(metname) <<
"The trajectory has not been smoothed!" << endl;
571 trajectoryCollection->
push_back(trajectory);
577 pair<bool, reco::Track> resultOfTrackExtrapAtPCA =
buildTrackAtPCA(trajectory, *beamSpot);
580 if (!resultOfTrackExtrapAtPCA.first) {
585 reco::Track& track = resultOfTrackExtrapAtPCA.second;
597 trackToTrackmap->insert(glbRef,
reco::TrackRef(trackCollectionRefProd, trackIndex++));
600 pair<bool, reco::Track> updateResult(
false,
reco::Track());
606 auto ih = recHitCollection->size();
607 t2t(trajectory, *recHitCollection, trajParams, chi2s);
608 auto ie = recHitCollection->size();
610 trackExtra.
setHits(recHitCollectionRefProd, ih, ie - ih);
615 for (; ih < ie; ++ih) {
616 auto const&
hit = (*recHitCollection)[ih];
618 for (
auto hh : hits) {
624 for (
auto hh : hits) {
625 if UNLIKELY (!updateResult.second.appendHitPattern(*
hh, ttopo))
632 trackExtraCollection->push_back(trackExtra);
637 LogTrace(metname) <<
"Debug Track being loaded pt " << track.
pt();
640 tjTkMap[iTjRef - 1] = iTkRef - 1;
644 LogTrace(metname) <<
"put the Collections in the event";
645 event.put(
std::move(recHitCollection), instance);
646 event.put(
std::move(trackExtraCollection), instance);
652 event.put(
std::move(trackToTrackmap), instance);
654 nonUpdatedHandle = returnTrackHandle;
661 auto trajTrackMap = std::make_unique<TrajTrackAssociationCollection>(rTrajs, nonUpdatedHandle);
664 for (std::map<unsigned int, unsigned int>::iterator
i = tjTkMap.begin();
i != tjTkMap.end();
i++) {
665 trajTrackMap->insert(
edm::Ref<std::vector<Trajectory>>(rTrajs, (*i).first),
668 event.put(
std::move(trajTrackMap), instance);
671 return returnTrackHandle;
676 const string metname =
"Muon|RecoMuon|MuonTrackLoader";
684 LogTrace(metname) <<
"Propagate to PCA...";
685 pair<bool, FreeTrajectoryState> extrapolationResult =
theUpdatorAtVtx->propagate(innerTSOS, beamSpot);
688 if (extrapolationResult.first)
689 ftsAtVtx = extrapolationResult.second;
692 LogInfo(metname) <<
"Track in the Tracker: taking the innermost state instead of the state at PCA";
696 LogInfo(metname) <<
"Propagation to PCA failed, taking the innermost state instead of the state at PCA";
699 LogInfo(metname) <<
"Stand Alone track: this track will be rejected";
700 return pair<bool, reco::Track>(
false,
reco::Track());
705 LogTrace(metname) <<
"TSOS after the extrapolation at vtx";
721 return pair<bool, reco::Track>(
true,
track);
726 const string metname =
"Muon|RecoMuon|MuonTrackLoader";
732 LogTrace(metname) <<
"Apply the vertex constraint";
733 pair<bool, FreeTrajectoryState> updateResult =
theUpdatorAtVtx->update(transientTrack, beamSpot);
735 if (!updateResult.first) {
736 return pair<bool, reco::Track>(
false,
reco::Track());
739 LogTrace(metname) <<
"FTS after the vertex constraint";
752 return pair<bool, reco::Track>(
true, updatedTrack);
756 const string metname =
"Muon|RecoMuon|MuonTrackLoader";
766 unsigned int innerId = 0, outerId = 0;
771 LogTrace(metname) <<
"alongMomentum";
779 LogTrace(metname) <<
"oppositeToMomentum";
787 LogError(metname) <<
"Wrong propagation direction!";
797 LogTrace(metname) <<
"The Global Muon outerMostMeasurementState is not compatible with the recHit detector! "
798 "Setting outerMost postition to recHit position if recHit isValid: "
799 << outerRecHit->isValid();
800 LogTrace(metname) <<
"From " << outerTSOSPos <<
" to " << hitPos;
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< reco::BeamSpot > theBeamSpotToken
std::unique_ptr< TrajectorySmoother > theSmoother
T getUntrackedParameter(std::string const &, T const &) const
MuonTrackLoader(edm::ParameterSet ¶meterSet, edm::ConsumesCollector &iC, const MuonServiceProxy *service=nullptr)
Constructor for the STA reco the args must be specify!
virtual int dimension() const =0
std::unique_ptr< MuonUpdatorAtVertex > theUpdatorAtVtx
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
static bool isInside(const GlobalPoint &)
ConstRecHitPointer const & recHit() const
virtual bool inside(const Local3DPoint &) const =0
Determine if the point is inside the bounds.
static PFTauRenderPlugin instance
const std::string metname
const CurvilinearTrajectoryError & curvilinearError() const
bool theSmoothTkTrackFlag
Global3DPoint GlobalPoint
std::vector< Track > TrackCollection
collection of Tracks
GlobalPoint globalPosition() const
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
ConstRecHitContainer recHits() const
static std::vector< const TrackingRecHit * > unpackHit(const TrackingRecHit &hit)
const Bounds & bounds() const
bool isNonnull() const
Checks for non-null.
TrackCharge charge() const
Log< level::Error, false > LogError
TrajectoryStateOnSurface geometricalInnermostState() const
const Plane & surface() const
The nominal surface of the GeomDet.
const CurvilinearTrajectoryError & curvilinearError() const
MuonCandidate::CandidateContainer CandidateContainer
const MuonServiceProxy * theService
void setGlobalTrack(reco::TrackRef glb)
set the ref to combined track
std::string dumpFTS(const FreeTrajectoryState &fts) const
PropagationDirection const & direction() const
edm::InputTag theBeamSpotInputTag
double chi2() const
chi-squared of the fit
void setTrackerTrack(reco::TrackRef tk)
set the ref to tracker's track
edm::OrphanHandle< reco::TrackCollection > loadTracks(TrajectoryContainer &, edm::Event &, const TrackerTopology &ttopo, const std::string &="", bool=true)
Convert the trajectories into tracks and load the tracks in the event.
double ndof() const
number of degrees of freedom of the fit
virtual ~MuonTrackLoader()
Destructor.
TrajectoryMeasurement const & lastMeasurement() const
double pt() const
track transverse momentum
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
FreeTrajectoryState const * freeState(bool withErrors=true) const
GlobalVector momentum() const
virtual std::vector< const TrackingRecHit * > recHits() const =0
Access to component RecHits (if any)
virtual TrajectorySmoother * clone() const =0
edm::RefToBase< TrajectorySeed > seedRef(void) const
GlobalVector momentum() const
MuonCandidate::TrajectoryContainer TrajectoryContainer
GlobalPoint position() const
Log< level::Info, false > LogInfo
GlobalPoint position() const
int ndof(bool bon=true) const
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
void setExtra(const TrackExtraRef &ref)
set reference to "extra" object
TrajectoryMeasurement const & firstMeasurement() const
ConstRecHitContainer RecHitContainer
const GlobalTrajectoryParameters & globalParameters() const
std::string theL2SeededTkLabel
Label for L2SeededTracks.
XYZVectorD XYZVector
spatial vector with cartesian internal representation
XYZPointD XYZPoint
point in space with cartesian internal representation
T getParameter(std::string const &) const
TrackingRecHit::ConstRecHitPointer ConstRecHitPointer
reco::TrackExtra buildTrackExtra(const Trajectory &) const
bool appendHitPattern(const TrackingRecHit &hit, const TrackerTopology &ttopo)
append a single hit to the HitPattern
void setSeedRef(const edm::RefToBase< TrajectorySeed > &seedRef)
std::pair< bool, reco::Track > buildTrackAtPCA(const Trajectory &trajectory, const reco::BeamSpot &) const
Build a track at the PCA WITHOUT any vertex constriant.
edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > theTrackerRecHitBuilderToken
void setStandAloneTrack(reco::TrackRef sta)
set the ref to stand alone track
static int position[264][3]
const MuonServiceProxy * theService
edm::ESGetToken< TrajectorySmoother, TrajectoryFitter::Record > theSmootherToken
TrajectoryStateOnSurface const & updatedState() const
DetId geographicalId() const
Log< level::Warning, false > LogWarning
std::pair< bool, reco::Track > buildTrackUpdatedAtPCA(const reco::Track &trackAtPCA, const reco::BeamSpot &) const
Takes a track at the PCA and applies the vertex constriant.
constexpr Detector det() const
get the detector field from this detid