46 : theService(service) {
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()) {
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();
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()) {
248 lastTsos = result.second;
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) {
291 std::reverse(navLayers.begin(), navLayers.end());
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()) {
470 result.push_back(*ihit);
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) {
730 std::reverse(hits.begin(), hits.end());
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();
799 std::reverse(hits.begin(), hits.end());
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()) {
822 LogTrace(
category_) <<
"pos" << pos <<
"radius " << pos.
perp() <<
" dim " << (*ir)->dimension() <<
" det "
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;
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))
bool empty() const
True if trajectory has no measurements.
void rescaleError(double factor)
void reverseTrajectoryPropagationDirection(Trajectory &) const
reverse the propagation direction of a trajectory
const Propagator * propagator() const
tuple ret
prodAgent to be discontinued
double t0(const DTRecSegment4D *deseg) const
std::pair< const_iterator, const_iterator > range
iterator range
TrajectoryStateOnSurface const & predictedState() const
const MeasurementEstimator * estimator() const
accasso at the propagator
ConstRecHitPointer const & recHit() const
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
std::string dumpLayer(const DetLayer *layer) const
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
std::vector< const DetLayer * > compatibleEndcapLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection) const
CosmicMuonSmoother * theSmoother
void estimateDirection(Trajectory &) const
check the direction of trajectory by checking eta spread
void makeFirstTime()
reset the theFirstTSOSFlag
TrajectoryStateOnSurface intermediateState(const TrajectoryStateOnSurface &) const
edm::Handle< CSCRecHit2DCollection > cschits_
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
unsigned long long theCacheId_DG
Global3DPoint GlobalPoint
virtual SubDetector subDetector() const =0
The type of detector (PixelBarrel, PixelEndcap, TIB, TOB, TID, TEC, CSC, DT, RPCBarrel, RPCEndcap)
MuonTrajectoryUpdator * backwardUpdator() const
GlobalPoint globalPosition() const
ConstRecHitContainer recHits() const
MuonCandidate::TrajectoryContainer TrajectoryContainer
std::string thePropagatorName
edm::Handle< DTRecHitCollection > dthits_
const Propagator * propagatorOpposite() const
void setEvent(const edm::Event &) override
pass the Event to the algo at each event
MuonDetLayerMeasurements * theLayerMeasurements
bool theTraversingMuonFlag
const CosmicMuonUtilities * utilities() const
DirectMuonNavigation * theNavigation
std::vector< TrajectoryMeasurementGroup > groupedMeasurements(const DetLayer *layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est, const edm::Event &iEvent)
TrajectoryContainer trajectories(const TrajectorySeed &) override
build trajectories from seed
constexpr std::array< uint8_t, layerIndexSize > layer
std::vector< const DetLayer * > compatibleLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection) const
std::string dumpMuonId(const DetId &id) const
PropagationDirection const & direction() const
C::const_iterator const_iterator
constant access iterator type
DataContainer const & measurements() const
DirectMuonNavigation * navigation() const
void flipTrajectory(Trajectory &) const
flip a trajectory with refit (the momentum direction is opposite)
MuonTrajectoryUpdator * updator() const
MuonRecHitContainer recHits(const DetLayer *layer, const edm::Event &iEvent)
returns the rechits which are on the layer
void reverseTrajectory(Trajectory &) const
reverse a trajectory without refit (out the measurements order changed)
MuonBestMeasurementFinder * theBestMeasurementFinder
void setFitDirection(NavigationDirection fitDirection)
set fit direction
TrajectoryMeasurement const & lastMeasurement() const
FreeTrajectoryState const * freeState(bool withErrors=true) const
if(conf_.getParameter< bool >("UseStripCablingDB"))
MuonTrajectoryUpdator * theBKUpdator
void incrementChamberCounters(const DetLayer *layer, int &dtChambers, int &cscChambers, int &rpcChambers, int &totalChambers)
bool hasPhi() const
Does it have the Phi projection?
~CosmicMuonTrajectoryBuilder() override
Destructor.
MeasurementContainer measurements(const DetLayer *layer, const GeomDet *det, const TrajectoryStateOnSurface &stateOnDet, const MeasurementEstimator &est, const edm::Event &iEvent)
GlobalVector momentum() const
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
std::vector< ConstRecHitPointer > ConstRecHitContainer
void getDirectionByTime(Trajectory &) const
check the direction of trajectory by checking the timing
GlobalPoint position() const
PropagationDirection checkDirectionByT0(const DTRecSegment4D *, const DTRecSegment4D *) const
TrajectoryMeasurement const & firstMeasurement() const
PTrajectoryStateOnDet const & startingState() const
std::vector< Trajectory > fit(const Trajectory &) const
edm::ParameterSet theNavigationPSet
T getParameter(std::string const &) const
MuonTrajectoryUpdator * theUpdator
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
const MuonServiceProxy * theService
void selectHits(MuonTransientTrackingRecHit::MuonRecHitContainer &) const
void setEvent(const edm::Event &)
set event
GlobalVector globalMomentum() const
TrajectoryContainer trajectories(const Trajectory &traj) const override
CosmicMuonTrajectoryBuilder(const edm::ParameterSet &, const MuonServiceProxy *service, edm::ConsumesCollector &iC)
Constructor.
const Propagator * propagatorAlong() const
TrajectoryMeasurement * findBestMeasurement(std::vector< TrajectoryMeasurement > &measC, const Propagator *propagator)
return the Tm with the best chi2: no cut applied.
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 &)
bool selfDuplicate(const Trajectory &) const
check if the trajectory iterates the same hit more than once
TrajectoryStateOnSurface const & updatedState() const
MuonTransientTrackingRecHit::MuonRecHitContainer unusedHits(const DetLayer *, const TrajectoryMeasurement &) const
double t0() const
Get the segment t0 (if recomputed, 0 is returned otherwise)
void reverseDirection(TrajectoryStateOnSurface &, const MagneticField *) const
void build(const TrajectoryStateOnSurface &, const NavigationDirection &, Trajectory &)
const BasicVectorType & basicVector() const
std::vector< MuonRecHitPointer > MuonRecHitContainer
GlobalVector globalDirection() const
T dot(const Basic3DVector &rh) const
Scalar product, or "dot" product, with a vector of same type.