49 bool enableDTMeasurement = par.
getParameter<
bool>(
"EnableDTMeasurement");
50 bool enableCSCMeasurement = par.
getParameter<
bool>(
"EnableCSCMeasurement");
51 bool enableRPCMeasurement = par.
getParameter<
bool>(
"EnableRPCMeasurement");
101 category_ =
"Muon|RecoMuon|CosmicMuon|CosmicMuonTrajectoryBuilder";
141 DetId did(ptsd1.detId());
151 vector<const DetLayer*> navLayers;
163 LogTrace(
category_) <<
"found " << navLayers.size() <<
" compatible DetLayers for the Seed";
165 if (navLayers.empty())
166 return emptyContainer;
168 vector<DetWithState> detsWithStates;
170 for (vector<const DetLayer*>::const_iterator
layer = navLayers.begin();
layer != navLayers.end();
layer++) {
176 LogTrace(
category_) <<
"Number of compatible dets: " << detsWithStates.size() << endl;
178 if (!detsWithStates.empty()) {
180 if (detsWithStates.front().second.isValid()) {
183 <<
debug.dumpLayer(navLayers.front());
184 lastTsos = detsWithStates.front().second;
189 detsWithStates.clear();
191 return emptyContainer;
211 int DTChamberUsedBack = 0;
212 int CSCChamberUsedBack = 0;
213 int RPCChamberUsedBack = 0;
214 int TotalChamberUsedBack = 0;
216 vector<TrajectoryMeasurement> measL;
220 for (vector<const DetLayer*>::const_iterator rnxtlayer = navLayers.begin(); rnxtlayer != navLayers.end();
225 <<
debug.dumpLayer(*rnxtlayer);
230 if (measL.empty() && (fabs(
theService->magneticField()->inTesla(
GlobalPoint(0, 0, 0)).z()) < 0.01) &&
231 (
theService->propagator(
"StraightLinePropagator").isValid())) {
239 for (vector<TrajectoryMeasurement>::const_iterator theMeas = measL.begin(); theMeas != measL.end(); ++theMeas) {
245 (*rnxtlayer), DTChamberUsedBack, CSCChamberUsedBack, RPCChamberUsedBack, TotalChamberUsedBack);
246 secondLast = lastTsos;
247 if ((!theTraj.
empty()) &&
result.second.isValid()) {
251 }
else if ((theMeas)->predictedState().
isValid())
252 lastTsos = (theMeas)->predictedState();
257 while (!theTraj.
empty()) {
261 if (!theTraj.
isValid() || TotalChamberUsedBack < 2 || (DTChamberUsedBack + CSCChamberUsedBack) == 0 ||
263 return emptyContainer;
267 DTChamberUsedBack = 0;
268 CSCChamberUsedBack = 0;
269 RPCChamberUsedBack = 0;
270 TotalChamberUsedBack = 0;
280 if (lastPos.basicVector().dot(momDir.
basicVector()) > 0) {
296 LogTrace(
category_) <<
"Begin backward refitting, with " << navLayers.size() <<
" layers" << endl;
298 for (vector<const DetLayer*>::const_iterator rnxtlayer = navLayers.begin(); rnxtlayer != navLayers.end();
306 for (MuonRecHitContainer::const_iterator ihit = tmpHits.begin(); ihit != tmpHits.end(); ++ihit) {
307 allUnusedHits.push_back(*ihit);
312 for (vector<TrajectoryMeasurement>::const_iterator theMeas = measL.begin(); theMeas != measL.end(); ++theMeas) {
314 if (rnxtlayer != navLayers.begin()) {
315 vector<const DetLayer*>::const_iterator lastlayer = rnxtlayer;
318 if ((*rnxtlayer)->location() != (*lastlayer)->location()) {
320 GlobalPoint thisPos = (theMeas)->predictedState().globalPosition();
324 if (momDir.
mag() > 0.01) {
333 (lastTsos.
globalPosition().
z() * (theMeas)->predictedState().globalPosition().z() < 0)) {
343 if (bkresult.first) {
345 (*rnxtlayer), DTChamberUsedBack, CSCChamberUsedBack, RPCChamberUsedBack, TotalChamberUsedBack);
349 allUnusedHits.insert(allUnusedHits.end(), tmpUnusedHits.begin(), tmpUnusedHits.end());
351 if ((!myTraj.
empty()) && bkresult.second.isValid())
352 lastTsos = bkresult.second;
353 else if ((theMeas)->predictedState().isValid())
354 lastTsos = (theMeas)->predictedState();
360 (DTChamberUsedBack + CSCChamberUsedBack) < 1) {
361 return emptyContainer;
371 return emptyContainer;
374 return emptyContainer;
383 return emptyContainer;
388 if (!smoothed.empty() && smoothed.front().foundHits() > 3) {
390 myTraj = smoothed.front();
420 return emptyContainer;
425 myTraj.
measurements().front().recHit()->globalPosition();
428 return emptyContainer;
435 << myTraj.
measurements().back().updatedState().globalMomentum() << endl;
437 << myTraj.
measurements().front().updatedState().globalMomentum() << endl;
447 if (
dir != propDir) {
452 return emptyContainer;
457 ret.emplace_back(std::make_unique<Trajectory>(myTraj));
468 for (MuonRecHitContainer::const_iterator ihit = tmpHits.begin(); ihit != tmpHits.end(); ++ihit) {
469 if ((*ihit)->geographicalId() != meas.
recHit()->geographicalId()) {
491 vector<const DetLayer*> navLayers;
516 if (navLayers.empty())
521 int DTChamberUsedBack = 0;
522 int CSCChamberUsedBack = 0;
523 int RPCChamberUsedBack = 0;
524 int TotalChamberUsedBack = 0;
537 vector<TrajectoryMeasurement> measL;
538 for (vector<const DetLayer*>::const_iterator rnxtlayer = navLayers.begin(); rnxtlayer != navLayers.end();
546 for (vector<TrajectoryMeasurement>::const_iterator theMeas = measL.begin(); theMeas != measL.end(); ++theMeas) {
548 if (bkresult.first) {
552 (*rnxtlayer), DTChamberUsedBack, CSCChamberUsedBack, RPCChamberUsedBack, TotalChamberUsedBack);
554 if ((!traj.
empty()) && bkresult.second.isValid())
555 lastTsos = bkresult.second;
556 else if ((theMeas)->predictedState().isValid())
557 lastTsos = (theMeas)->predictedState();
605 if (predTsos.isValid())
606 LogTrace(
category_) <<
"intermediateState: a intermediate state: pos: " << predTsos.globalPosition()
607 <<
"mom: " << predTsos.globalMomentum();
620 vector<bool>
keep(
hits.size(),
true);
624 for (MuonRecHitContainer::const_iterator ihit =
hits.begin(); ihit !=
hits.end(); ++ihit) {
630 for (MuonRecHitContainer::const_iterator ihit2 = ihit + 1; ihit2 !=
hits.end(); ++ihit2) {
635 if ((*ihit)->geographicalId() == (*ihit2)->geographicalId()) {
636 if ((*ihit)->dimension() > (*ihit2)->dimension()) {
638 }
else if ((*ihit)->dimension() < (*ihit2)->dimension()) {
641 if ((*ihit)->transientHits().size() > (*ihit2)->transientHits().size()) {
643 }
else if ((*ihit)->transientHits().size() < (*ihit2)->transientHits().size()) {
645 }
else if ((*ihit)->degreesOfFreedom() != 0 && (*ihit2)->degreesOfFreedom() != 0) {
646 if (((*ihit)->chi2() / (*ihit)->degreesOfFreedom()) > ((*ihit2)->chi2() / (*ihit)->degreesOfFreedom()))
659 for (MuonRecHitContainer::const_iterator ihit =
hits.begin(); ihit !=
hits.end(); ++ihit) {
661 tmp.push_back(*ihit);
681 for (ConstRecHitContainer::const_iterator ir =
hits.begin(); ir !=
hits.end(); ir++) {
682 if (!(*ir)->isValid())
684 for (ConstRecHitContainer::const_iterator ir2 = ir + 1; ir2 !=
hits.end(); ir2++) {
685 if (!(*ir2)->isValid())
714 std::vector<TrajectoryMeasurement>
const& meas = traj.
measurements();
715 for (
auto itm = meas.rbegin(); itm != meas.rend(); ++itm) {
737 if (refittedback.empty()) {
741 LogTrace(
category_) <<
"flipTrajectory: first " << refittedback.front().firstMeasurement().updatedState()
742 <<
"\nflipTrajectory: last " << refittedback.front().lastMeasurement().updatedState();
744 traj = refittedback.front();
757 const std::vector<TrajectoryMeasurement>& meas = traj.
measurements();
759 for (std::vector<TrajectoryMeasurement>::const_iterator itm = meas.begin(); itm != meas.end(); ++itm) {
763 while (!traj.
empty()) {
795 if (!refitted.empty())
796 traj = refitted.front();
802 if (!refittedback.empty())
803 traj = refittedback.front();
815 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator ir =
hits.begin(); ir !=
hits.end(); ir++) {
816 if (!(*ir)->isValid()) {
823 << (*ir)->det()->geographicalId().det() <<
" sub det " << (*ir)->det()->subDetector() << endl;
825 if ((*ir)->det()->geographicalId().det() == 2 && (*ir)->det()->subDetector() == 6) {
830 if ((*rechit).isValid())
834 if ((*ir)->det()->geographicalId().det() == 2 && (*ir)->det()->subDetector() == 7) {
839 if ((*rechit).isValid())
856 std::vector<TrajectoryMeasurement>
result;
857 std::vector<TrajectoryMeasurement> measurements;
859 if (
layer->hasGroups()) {
860 std::vector<TrajectoryMeasurementGroup> measurementGroups =
863 for (std::vector<TrajectoryMeasurementGroup>::const_iterator tmGroupItr = measurementGroups.begin();
864 tmGroupItr != measurementGroups.end();
866 measurements = tmGroupItr->measurements();
871 result.push_back(*bestMeasurement);
879 result.push_back(*bestMeasurement);
881 measurements.clear();
890 const DetLayer*
layer,
int& dtChambers,
int& cscChambers,
int& rpcChambers,
int& totalChambers) {
905 if ((dtseg ==
nullptr) || (!dtseg->
hasPhi()))
932 if (dtseg1 == dtseg2 ||
t0(dtseg1) ==
t0(dtseg2))
void reverseDirection(TrajectoryStateOnSurface &, const MagneticField *) const
void rescaleError(double factor)
T getParameter(std::string const &) const
std::pair< const_iterator, const_iterator > range
iterator range
TrajectoryStateOnSurface const & predictedState() const
std::vector< const DetLayer * > compatibleEndcapLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection) const
std::vector< const DetLayer * > compatibleLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection) const
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
bool hasPhi() const
Does it have the Phi projection?
CosmicMuonSmoother * theSmoother
double t0() const
Get the segment t0 (if recomputed, 0 is returned otherwise)
void makeFirstTime()
reset the theFirstTSOSFlag
edm::Handle< CSCRecHit2DCollection > cschits_
ret
prodAgent to be discontinued
MuonTransientTrackingRecHit::MuonRecHitContainer unusedHits(const DetLayer *, const TrajectoryMeasurement &) const
void reverseTrajectory(Trajectory &) const
reverse a trajectory without refit (out the measurements order changed)
unsigned long long theCacheId_DG
const Propagator * propagatorAlong() const
const Propagator * propagator() const
Global3DPoint GlobalPoint
void reverseTrajectoryPropagationDirection(Trajectory &) const
reverse the propagation direction of a trajectory
bool selfDuplicate(const Trajectory &) const
check if the trajectory iterates the same hit more than once
MuonCandidate::TrajectoryContainer TrajectoryContainer
std::string thePropagatorName
edm::Handle< DTRecHitCollection > dthits_
void setEvent(const edm::Event &) override
pass the Event to the algo at each event
void getDirectionByTime(Trajectory &) const
check the direction of trajectory by checking the timing
MuonDetLayerMeasurements * theLayerMeasurements
bool theTraversingMuonFlag
DirectMuonNavigation * theNavigation
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
MuonTrajectoryUpdator * backwardUpdator() const
double t0(const DTRecSegment4D *deseg) const
std::vector< TrajectoryMeasurementGroup > groupedMeasurements(const DetLayer *layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est, const edm::Event &iEvent)
TrajectoryMeasurement const & lastMeasurement() const
void estimateDirection(Trajectory &) const
check the direction of trajectory by checking eta spread
TrajectoryContainer trajectories(const TrajectorySeed &) override
build trajectories from seed
DataContainer const & measurements() const
GlobalPoint position() const
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
C::const_iterator const_iterator
constant access iterator type
PropagationDirection checkDirectionByT0(const DTRecSegment4D *, const DTRecSegment4D *) const
GlobalPoint globalPosition() const
MuonRecHitContainer recHits(const DetLayer *layer, const edm::Event &iEvent)
returns the rechits which are on the layer
MuonBestMeasurementFinder * theBestMeasurementFinder
const CosmicMuonUtilities * utilities() const
void setFitDirection(NavigationDirection fitDirection)
set fit direction
PropagationDirection const & direction() const
ConstRecHitContainer recHits() const
GlobalVector momentum() const
MuonTrajectoryUpdator * theBKUpdator
void incrementChamberCounters(const DetLayer *layer, int &dtChambers, int &cscChambers, int &rpcChambers, int &totalChambers)
std::vector< Trajectory > fit(const Trajectory &) const
~CosmicMuonTrajectoryBuilder() override
Destructor.
MeasurementContainer measurements(const DetLayer *layer, const GeomDet *det, const TrajectoryStateOnSurface &stateOnDet, const MeasurementEstimator &est, const edm::Event &iEvent)
const BasicVectorType & basicVector() const
void selectHits(MuonTransientTrackingRecHit::MuonRecHitContainer &) const
std::vector< ConstRecHitPointer > ConstRecHitContainer
TrajectoryStateOnSurface intermediateState(const TrajectoryStateOnSurface &) const
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
edm::ParameterSet theNavigationPSet
GlobalVector globalDirection() const
DirectMuonNavigation * navigation() const
bool empty() const
True if trajectory has no measurements.
MuonTrajectoryUpdator * updator() const
GlobalVector globalMomentum() const
MuonTrajectoryUpdator * theUpdator
TrajectoryStateOnSurface const & updatedState() const
const MuonServiceProxy * theService
void setEvent(const edm::Event &)
set event
const MeasurementEstimator * estimator() const
accasso at the propagator
TrajectoryMeasurement const & firstMeasurement() const
void flipTrajectory(Trajectory &) const
flip a trajectory with refit (the momentum direction is opposite)
TrajectoryContainer trajectories(const Trajectory &traj) const override
CosmicMuonTrajectoryBuilder(const edm::ParameterSet &, const MuonServiceProxy *service, edm::ConsumesCollector &iC)
Constructor.
TrajectoryMeasurement * findBestMeasurement(std::vector< TrajectoryMeasurement > &measC, const Propagator *propagator)
return the Tm with the best chi2: no cut applied.
FreeTrajectoryState const * freeState(bool withErrors=true) const
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
std::vector< TrajectoryMeasurement > findBestMeasurements(const DetLayer *, const TrajectoryStateOnSurface &, const Propagator *, const MeasurementEstimator *)
virtual std::pair< bool, TrajectoryStateOnSurface > update(const TrajectoryMeasurement *measurement, Trajectory &trajectory, const Propagator *propagator)
update the Trajectory with the TrajectoryMeasurement
void buildSecondHalf(Trajectory &)
void build(const TrajectoryStateOnSurface &, const NavigationDirection &, Trajectory &)
T dot(const Basic3DVector &rh) const
Scalar product, or "dot" product, with a vector of same type.
std::vector< MuonRecHitPointer > MuonRecHitContainer
ConstRecHitPointer const & recHit() const
const Propagator * propagatorOpposite() const