CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
CosmicMuonTrajectoryBuilder Class Reference

#include <CosmicMuonTrajectoryBuilder.h>

Inheritance diagram for CosmicMuonTrajectoryBuilder:
MuonTrajectoryBuilder

Public Member Functions

MuonTrajectoryUpdatorbackwardUpdator () const
 
MuonBestMeasurementFinderbestMeasurementFinder () const
 
PropagationDirection checkDirectionByT0 (const DTRecSegment4D *, const DTRecSegment4D *) const
 
 CosmicMuonTrajectoryBuilder (const edm::ParameterSet &, const MuonServiceProxy *service, edm::ConsumesCollector &iC)
 Constructor. More...
 
DirectMuonNavigationnavigation () const
 
const Propagatorpropagator () const
 
const PropagatorpropagatorAlong () const
 
const PropagatorpropagatorOpposite () const
 
void setEvent (const edm::Event &) override
 pass the Event to the algo at each event More...
 
CosmicMuonSmoothersmoother () const
 
double t0 (const DTRecSegment4D *deseg) const
 
std::vector< Trajectory * > trajectories (const TrajectorySeed &) override
 build trajectories from seed More...
 
CandidateContainer trajectories (const TrackCand &) override
 dummy implementation, unused in this class More...
 
MuonTrajectoryUpdatorupdator () const
 
const CosmicMuonUtilitiesutilities () const
 
 ~CosmicMuonTrajectoryBuilder () override
 Destructor. More...
 
- Public Member Functions inherited from MuonTrajectoryBuilder
 MuonTrajectoryBuilder ()
 constructor More...
 
virtual ~MuonTrajectoryBuilder ()
 destructor More...
 

Private Member Functions

void build (const TrajectoryStateOnSurface &, const NavigationDirection &, Trajectory &)
 
void buildSecondHalf (Trajectory &)
 
void estimateDirection (Trajectory &) const
 check the direction of trajectory by checking eta spread More...
 
std::vector< TrajectoryMeasurementfindBestMeasurements (const DetLayer *, const TrajectoryStateOnSurface &, const Propagator *, const MeasurementEstimator *)
 
void flipTrajectory (Trajectory &) const
 flip a trajectory with refit (the momentum direction is opposite) More...
 
void getDirectionByTime (Trajectory &) const
 check the direction of trajectory by checking the timing More...
 
void incrementChamberCounters (const DetLayer *layer, int &dtChambers, int &cscChambers, int &rpcChambers, int &totalChambers)
 
TrajectoryStateOnSurface intermediateState (const TrajectoryStateOnSurface &) const
 
void reverseTrajectory (Trajectory &) const
 reverse a trajectory without refit (out the measurements order changed) More...
 
void reverseTrajectoryPropagationDirection (Trajectory &) const
 reverse the propagation direction of a trajectory More...
 
void selectHits (MuonTransientTrackingRecHit::MuonRecHitContainer &) const
 
bool selfDuplicate (const Trajectory &) const
 check if the trajectory iterates the same hit more than once More...
 
MuonTransientTrackingRecHit::MuonRecHitContainer unusedHits (const DetLayer *, const TrajectoryMeasurement &) const
 

Private Attributes

std::string category_
 
edm::Handle< CSCRecHit2DCollectioncschits_
 
edm::Handle< DTRecHitCollectiondthits_
 
MuonBestMeasurementFindertheBestMeasurementFinder
 
MuonTrajectoryUpdatortheBKUpdator
 
unsigned long long theCacheId_DG
 
MuonDetLayerMeasurementstheLayerMeasurements
 
DirectMuonNavigationtheNavigation
 
edm::ParameterSet theNavigationPSet
 
int theNSuccess
 
int theNTraversing
 
std::string thePropagatorName
 
const MuonServiceProxytheService
 
CosmicMuonSmoothertheSmoother
 
bool theStrict1LegFlag
 
bool theTraversingMuonFlag
 
MuonTrajectoryUpdatortheUpdator
 

Additional Inherited Members

- Public Types inherited from MuonTrajectoryBuilder
typedef MuonCandidate::CandidateContainer CandidateContainer
 
typedef std::pair< const Trajectory *, reco::TrackRefTrackCand
 
typedef MuonCandidate::TrajectoryContainer TrajectoryContainer
 

Detailed Description

Definition at line 41 of file CosmicMuonTrajectoryBuilder.h.

Constructor & Destructor Documentation

CosmicMuonTrajectoryBuilder::CosmicMuonTrajectoryBuilder ( const edm::ParameterSet par,
const MuonServiceProxy service,
edm::ConsumesCollector iC 
)

Constructor.

Definition at line 43 of file CosmicMuonTrajectoryBuilder.cc.

References category_, HLT_2018_cff::CSCRecSegmentLabel, HLT_2018_cff::DTRecSegmentLabel, edm::ParameterSet::getParameter(), insideOut, outsideIn, HLT_2018_cff::RPCRecSegmentLabel, theBestMeasurementFinder, theBKUpdator, theCacheId_DG, theLayerMeasurements, theNavigation, theNavigationPSet, theNSuccess, theNTraversing, thePropagatorName, theService, theSmoother, theStrict1LegFlag, theTraversingMuonFlag, and theUpdator.

46  : theService(service) {
47  thePropagatorName = par.getParameter<string>("Propagator");
48 
49  bool enableDTMeasurement = par.getParameter<bool>("EnableDTMeasurement");
50  bool enableCSCMeasurement = par.getParameter<bool>("EnableCSCMeasurement");
51  bool enableRPCMeasurement = par.getParameter<bool>("EnableRPCMeasurement");
52 
53  // if(enableDTMeasurement)
54  InputTag DTRecSegmentLabel = par.getParameter<InputTag>("DTRecSegmentLabel");
55 
56  // if(enableCSCMeasurement)
57  InputTag CSCRecSegmentLabel = par.getParameter<InputTag>("CSCRecSegmentLabel");
58 
59  // if(enableRPCMeasurement)
60  InputTag RPCRecSegmentLabel = par.getParameter<InputTag>("RPCRecSegmentLabel");
61 
62  // if(enableGEMMeasurement)
63  // InputTag GEMRecSegmentLabel = par.getParameter<InputTag>("GEMRecSegmentLabel");
64 
65  theLayerMeasurements = new MuonDetLayerMeasurements(DTRecSegmentLabel,
66  CSCRecSegmentLabel,
67  RPCRecSegmentLabel,
68  edm::InputTag(),
69  edm::InputTag(),
70  iC,
71  enableDTMeasurement,
72  enableCSCMeasurement,
73  enableRPCMeasurement,
74  false,
75  false);
76 
77  ParameterSet muonUpdatorPSet = par.getParameter<ParameterSet>("MuonTrajectoryUpdatorParameters");
78 
79  theNavigation = nullptr; // new DirectMuonNavigation(theService->detLayerGeometry());
80  theUpdator = new MuonTrajectoryUpdator(muonUpdatorPSet, insideOut);
81 
83 
84  ParameterSet muonBackwardUpdatorPSet = par.getParameter<ParameterSet>("BackwardMuonTrajectoryUpdatorParameters");
85 
86  theBKUpdator = new MuonTrajectoryUpdator(muonBackwardUpdatorPSet, outsideIn);
87 
88  theTraversingMuonFlag = par.getParameter<bool>("BuildTraversingMuon");
89 
90  theStrict1LegFlag = par.getParameter<bool>("Strict1Leg");
91 
92  ParameterSet smootherPSet = par.getParameter<ParameterSet>("MuonSmootherParameters");
93 
94  theNavigationPSet = par.getParameter<ParameterSet>("MuonNavigationParameters");
95 
96  theSmoother = new CosmicMuonSmoother(smootherPSet, theService);
97 
98  theNTraversing = 0;
99  theNSuccess = 0;
100  theCacheId_DG = 0;
101  category_ = "Muon|RecoMuon|CosmicMuon|CosmicMuonTrajectoryBuilder";
102 }
T getParameter(std::string const &) const
MuonDetLayerMeasurements * theLayerMeasurements
MuonBestMeasurementFinder * theBestMeasurementFinder
CosmicMuonTrajectoryBuilder::~CosmicMuonTrajectoryBuilder ( )
override

Destructor.

Definition at line 104 of file CosmicMuonTrajectoryBuilder.cc.

References category_, LogTrace, theBestMeasurementFinder, theBKUpdator, theLayerMeasurements, theNavigation, theNSuccess, theNTraversing, theSmoother, and theUpdator.

104  {
105  LogTrace(category_) << "CosmicMuonTrajectoryBuilder dtor called";
106  if (theUpdator)
107  delete theUpdator;
108  if (theBKUpdator)
109  delete theBKUpdator;
111  delete theLayerMeasurements;
112  if (theSmoother)
113  delete theSmoother;
114  if (theNavigation)
115  delete theNavigation;
117 
118  LogTrace(category_) << "CosmicMuonTrajectoryBuilder Traversing: " << theNSuccess << "/" << theNTraversing;
119 }
MuonDetLayerMeasurements * theLayerMeasurements
MuonBestMeasurementFinder * theBestMeasurementFinder
#define LogTrace(id)

Member Function Documentation

MuonTrajectoryUpdator* CosmicMuonTrajectoryBuilder::backwardUpdator ( ) const
inline

Definition at line 66 of file CosmicMuonTrajectoryBuilder.h.

Referenced by build(), and trajectories().

66 { return theBKUpdator; }
MuonBestMeasurementFinder* CosmicMuonTrajectoryBuilder::bestMeasurementFinder ( ) const
inline
void CosmicMuonTrajectoryBuilder::build ( const TrajectoryStateOnSurface ts,
const NavigationDirection startingDir,
Trajectory traj 
)
private

Definition at line 489 of file CosmicMuonTrajectoryBuilder.cc.

References alongMomentum, backwardUpdator(), PV3DBase< T, PVType, FrameType >::basicVector(), category_, DirectMuonNavigation::compatibleEndcapLayers(), DirectMuonNavigation::compatibleLayers(), Basic3DVector< T >::dot(), Trajectory::empty(), Basic3DVector< T >::eta(), findBestMeasurements(), Trajectory::firstMeasurement(), TrajectoryStateOnSurface::freeState(), TrajectoryStateOnSurface::globalPosition(), incrementChamberCounters(), TrajectoryStateOnSurface::isValid(), Trajectory::lastMeasurement(), LogTrace, MuonTrajectoryUpdator::makeFirstTime(), FreeTrajectoryState::momentum(), navigation(), oppositeToMomentum, FreeTrajectoryState::position(), Propagator::propagate(), propagator(), propagatorAlong(), propagatorOpposite(), rpcPointValidation_cfi::recHit, TrajectoryStateOnSurface::rescaleError(), MuonTrajectoryUpdator::setFitDirection(), theBKUpdator, theStrict1LegFlag, theTraversingMuonFlag, MuonTrajectoryUpdator::update(), TrajectoryMeasurement::updatedState(), updator(), and PV3DBase< T, PVType, FrameType >::y().

Referenced by buildSecondHalf().

491  {
492  if (!ts.isValid())
493  return;
494 
495  const FreeTrajectoryState* fts = ts.freeState();
496  if (!fts)
497  return;
498 
499  vector<const DetLayer*> navLayers;
500 
501  if (fabs(fts->momentum().basicVector().eta()) < 1.0) {
502  //DT
503  if (fts->position().basicVector().dot(fts->momentum().basicVector()) > 0) {
504  navLayers = navigation()->compatibleLayers((*fts), alongMomentum);
505  } else {
506  navLayers = navigation()->compatibleLayers((*fts), oppositeToMomentum);
507  }
508 
510  //CSC
511  if (fts->position().basicVector().dot(fts->momentum().basicVector()) > 0) {
512  navLayers = navigation()->compatibleEndcapLayers((*fts), alongMomentum);
513  } else {
514  navLayers = navigation()->compatibleEndcapLayers((*fts), oppositeToMomentum);
515  }
516  } else {
517  if (fts->position().basicVector().dot(fts->momentum().basicVector()) > 0) {
518  navLayers = navigation()->compatibleLayers((*fts), alongMomentum);
519  } else {
520  navLayers = navigation()->compatibleLayers((*fts), oppositeToMomentum);
521  }
522  }
523 
524  if (navLayers.empty())
525  return;
526 
527  theBKUpdator->setFitDirection(startingDir);
528 
529  int DTChamberUsedBack = 0;
530  int CSCChamberUsedBack = 0;
531  int RPCChamberUsedBack = 0;
532  int TotalChamberUsedBack = 0;
533 
536  ? propagatorAlong()->propagate((*fts), navLayers.front()->surface())
537  : propagatorOpposite()->propagate((*fts), navLayers.front()->surface());
538 
539  if (!lastTsos.isValid()) {
540  LogTrace(category_) << "propagation failed from fts to inner cylinder";
541  return;
542  }
543  LogTrace(category_) << "tsos " << lastTsos.globalPosition();
544  lastTsos.rescaleError(10.);
545  vector<TrajectoryMeasurement> measL;
546  for (vector<const DetLayer*>::const_iterator rnxtlayer = navLayers.begin(); rnxtlayer != navLayers.end();
547  ++rnxtlayer) {
548  measL.clear();
549  measL = findBestMeasurements(*rnxtlayer, lastTsos, propagator(), (backwardUpdator()->estimator()));
550 
551  if (measL.empty())
552  continue;
553 
554  for (vector<TrajectoryMeasurement>::const_iterator theMeas = measL.begin(); theMeas != measL.end(); ++theMeas) {
555  pair<bool, TrajectoryStateOnSurface> bkresult = backwardUpdator()->update((&*theMeas), traj, propagator());
556  if (bkresult.first) {
557  LogTrace(category_) << "update ok : " << (theMeas)->recHit()->globalPosition();
558 
560  (*rnxtlayer), DTChamberUsedBack, CSCChamberUsedBack, RPCChamberUsedBack, TotalChamberUsedBack);
561 
562  if ((!traj.empty()) && bkresult.second.isValid())
563  lastTsos = bkresult.second;
564  else if ((theMeas)->predictedState().isValid())
565  lastTsos = (theMeas)->predictedState();
566  }
567  }
568  }
569  navLayers.clear();
570  updator()->makeFirstTime();
572 
573  measL.clear();
574 
575  return;
576 }
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:233
const Propagator * propagator() const
std::vector< const DetLayer * > compatibleEndcapLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection) const
void makeFirstTime()
reset the theFirstTSOSFlag
T y() const
Definition: PV3DBase.h:60
MuonTrajectoryUpdator * backwardUpdator() const
GlobalPoint globalPosition() const
const Propagator * propagatorOpposite() const
std::vector< const DetLayer * > compatibleLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection) const
DirectMuonNavigation * navigation() const
MuonTrajectoryUpdator * updator() const
void setFitDirection(NavigationDirection fitDirection)
set fit direction
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:150
FreeTrajectoryState const * freeState(bool withErrors=true) const
void incrementChamberCounters(const DetLayer *layer, int &dtChambers, int &cscChambers, int &rpcChambers, int &totalChambers)
#define LogTrace(id)
GlobalVector momentum() const
GlobalPoint position() const
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:166
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
const Propagator * propagatorAlong() const
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
TrajectoryStateOnSurface const & updatedState() const
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
T dot(const Basic3DVector &rh) const
Scalar product, or "dot" product, with a vector of same type.
void CosmicMuonTrajectoryBuilder::buildSecondHalf ( Trajectory traj)
private

Definition at line 582 of file CosmicMuonTrajectoryBuilder.cc.

References build(), category_, Trajectory::empty(), Trajectory::firstMeasurement(), TrajectoryStateOnSurface::globalMomentum(), TrajectoryStateOnSurface::globalPosition(), insideOut, intermediateState(), TrajectoryStateOnSurface::isValid(), Trajectory::lastMeasurement(), LogTrace, TrajectoryMeasurement::predictedState(), TrajectoryMeasurement::recHit(), reverseTrajectory(), and TrajectoryMeasurement::updatedState().

Referenced by trajectories().

582  {
583  if ((traj.firstMeasurement().recHit()->globalPosition().perp() <
584  traj.lastMeasurement().recHit()->globalPosition().perp())) {
585  LogTrace(category_) << "inside-out: reverseTrajectory";
586  reverseTrajectory(traj);
587  }
588  if (traj.empty())
589  return;
591  if (!tsos.isValid())
592  tsos = traj.lastMeasurement().predictedState();
593  LogTrace(category_) << "last tsos on traj: pos: " << tsos.globalPosition() << " mom: " << tsos.globalMomentum();
594  if (!tsos.isValid()) {
595  LogTrace(category_) << "last tsos on traj invalid";
596  return;
597  }
598 
599  build(intermediateState(tsos), insideOut, traj);
600 
601  return;
602 }
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:233
TrajectoryStateOnSurface const & predictedState() const
ConstRecHitPointer const & recHit() const
TrajectoryStateOnSurface intermediateState(const TrajectoryStateOnSurface &) const
GlobalPoint globalPosition() const
void reverseTrajectory(Trajectory &) const
reverse a trajectory without refit (out the measurements order changed)
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:150
#define LogTrace(id)
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:166
GlobalVector globalMomentum() const
TrajectoryStateOnSurface const & updatedState() const
void build(const TrajectoryStateOnSurface &, const NavigationDirection &, Trajectory &)
PropagationDirection CosmicMuonTrajectoryBuilder::checkDirectionByT0 ( const DTRecSegment4D dtseg1,
const DTRecSegment4D dtseg2 
) const

Definition at line 937 of file CosmicMuonTrajectoryBuilder.cc.

References alongMomentum, anyDirection, category_, LogTrace, oppositeToMomentum, mps_fire::result, and t0().

938  {
939  LogTrace(category_) << "comparing dtseg: " << dtseg1 << " " << dtseg2 << endl;
940  if (dtseg1 == dtseg2 || t0(dtseg1) == t0(dtseg2))
941  return anyDirection;
942 
944 
945  return result;
946 }
double t0(const DTRecSegment4D *deseg) const
PropagationDirection
#define LogTrace(id)
void CosmicMuonTrajectoryBuilder::estimateDirection ( Trajectory traj) const
private

check the direction of trajectory by checking eta spread

Definition at line 781 of file CosmicMuonTrajectoryBuilder.cc.

References category_, PV3DBase< T, PVType, FrameType >::eta(), Trajectory::firstMeasurement(), TrajectoryStateOnSurface::globalMomentum(), TrajectoryStateOnSurface::globalPosition(), hfClusterShapes_cfi::hits, TrajectoryStateOnSurface::isValid(), Trajectory::lastMeasurement(), LogTrace, Trajectory::recHits(), groupFilesInBlocks::reverse, CosmicMuonUtilities::reverseDirection(), Trajectory::seed(), theService, theSmoother, CosmicMuonSmoother::trajectories(), TrajectoryMeasurement::updatedState(), and utilities().

Referenced by trajectories().

781  {
783 
785 
787 
788  if (!firstTSOS.isValid() || !lastTSOS.isValid())
789  return;
790 
791  LogTrace(category_) << "Two ends of the traj " << firstTSOS.globalPosition() << ", " << lastTSOS.globalPosition();
792 
793  LogTrace(category_) << "Their mom: " << firstTSOS.globalMomentum() << ", " << lastTSOS.globalMomentum();
794 
795  LogTrace(category_) << "Their mom eta: " << firstTSOS.globalMomentum().eta() << ", "
796  << lastTSOS.globalMomentum().eta();
797 
798  // momentum eta can be used to estimate direction
799  // the beam-halo muon seems enter with a larger |eta|
800 
801  if (fabs(firstTSOS.globalMomentum().eta()) > fabs(lastTSOS.globalMomentum().eta())) {
802  vector<Trajectory> refitted = theSmoother->trajectories(traj.seed(), hits, firstTSOS);
803  if (!refitted.empty())
804  traj = refitted.front();
805 
806  } else {
807  std::reverse(hits.begin(), hits.end());
808  utilities()->reverseDirection(lastTSOS, &*theService->magneticField());
809  vector<Trajectory> refittedback = theSmoother->trajectories(traj.seed(), hits, lastTSOS);
810  if (!refittedback.empty())
811  traj = refittedback.front();
812  }
813 
814  return;
815 }
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:263
GlobalPoint globalPosition() const
ConstRecHitContainer recHits() const
Definition: Trajectory.h:186
const CosmicMuonUtilities * utilities() const
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:150
#define LogTrace(id)
std::vector< ConstRecHitPointer > ConstRecHitContainer
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:166
T eta() const
Definition: PV3DBase.h:73
GlobalVector globalMomentum() const
TrajectoryStateOnSurface const & updatedState() const
void reverseDirection(TrajectoryStateOnSurface &, const MagneticField *) const
TrajectoryContainer trajectories(const Trajectory &traj) const override
std::vector< TrajectoryMeasurement > CosmicMuonTrajectoryBuilder::findBestMeasurements ( const DetLayer layer,
const TrajectoryStateOnSurface tsos,
const Propagator propagator,
const MeasurementEstimator estimator 
)
private

Definition at line 859 of file CosmicMuonTrajectoryBuilder.cc.

References MuonBestMeasurementFinder::findBestMeasurement(), MuonDetLayerMeasurements::groupedMeasurements(), GeometricSearchDet::hasGroups(), MuonDetLayerMeasurements::measurements(), mps_fire::result, theBestMeasurementFinder, and theLayerMeasurements.

Referenced by build(), and trajectories().

863  {
864  std::vector<TrajectoryMeasurement> result;
865  std::vector<TrajectoryMeasurement> measurements;
866 
867  if (layer->hasGroups()) {
868  std::vector<TrajectoryMeasurementGroup> measurementGroups =
869  theLayerMeasurements->groupedMeasurements(layer, tsos, *propagator, *estimator);
870 
871  for (std::vector<TrajectoryMeasurementGroup>::const_iterator tmGroupItr = measurementGroups.begin();
872  tmGroupItr != measurementGroups.end();
873  ++tmGroupItr) {
874  measurements = tmGroupItr->measurements();
875  const TrajectoryMeasurement* bestMeasurement =
876  theBestMeasurementFinder->findBestMeasurement(measurements, propagator);
877 
878  if (bestMeasurement)
879  result.push_back(*bestMeasurement);
880  }
881  } else {
882  measurements = theLayerMeasurements->measurements(layer, tsos, *propagator, *estimator);
883  const TrajectoryMeasurement* bestMeasurement =
884  theBestMeasurementFinder->findBestMeasurement(measurements, propagator);
885 
886  if (bestMeasurement)
887  result.push_back(*bestMeasurement);
888  }
889  measurements.clear();
890 
891  return result;
892 }
MuonDetLayerMeasurements * theLayerMeasurements
std::vector< TrajectoryMeasurementGroup > groupedMeasurements(const DetLayer *layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est, const edm::Event &iEvent)
MuonBestMeasurementFinder * theBestMeasurementFinder
MeasurementContainer measurements(const DetLayer *layer, const GeomDet *det, const TrajectoryStateOnSurface &stateOnDet, const MeasurementEstimator &est, const edm::Event &iEvent)
TrajectoryMeasurement * findBestMeasurement(std::vector< TrajectoryMeasurement > &measC, const Propagator *propagator)
return the Tm with the best chi2: no cut applied.
void CosmicMuonTrajectoryBuilder::flipTrajectory ( Trajectory traj) const
private

flip a trajectory with refit (the momentum direction is opposite)

Definition at line 732 of file CosmicMuonTrajectoryBuilder.cc.

References category_, CosmicMuonSmoother::fit(), hfClusterShapes_cfi::hits, TrajectoryStateOnSurface::isValid(), Trajectory::lastMeasurement(), LogTrace, Trajectory::recHits(), groupFilesInBlocks::reverse, CosmicMuonUtilities::reverseDirection(), Trajectory::seed(), theService, theSmoother, TrajectoryMeasurement::updatedState(), and utilities().

Referenced by trajectories().

732  {
734  if (!lastTSOS.isValid()) {
735  LogTrace(category_) << "Error: last TrajectoryState invalid.";
736  }
738  std::reverse(hits.begin(), hits.end());
739 
740  LogTrace(category_) << "last tsos before flipping " << lastTSOS;
741  utilities()->reverseDirection(lastTSOS, &*theService->magneticField());
742  LogTrace(category_) << "last tsos after flipping " << lastTSOS;
743 
744  vector<Trajectory> refittedback = theSmoother->fit(traj.seed(), hits, lastTSOS);
745  if (refittedback.empty()) {
746  LogTrace(category_) << "flipTrajectory fail. " << endl;
747  return;
748  }
749  LogTrace(category_) << "flipTrajectory: first " << refittedback.front().firstMeasurement().updatedState()
750  << "\nflipTrajectory: last " << refittedback.front().lastMeasurement().updatedState();
751 
752  traj = refittedback.front();
753 
754  return;
755 }
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:263
ConstRecHitContainer recHits() const
Definition: Trajectory.h:186
const CosmicMuonUtilities * utilities() const
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:150
#define LogTrace(id)
std::vector< ConstRecHitPointer > ConstRecHitContainer
std::vector< Trajectory > fit(const Trajectory &) const
TrajectoryStateOnSurface const & updatedState() const
void reverseDirection(TrajectoryStateOnSurface &, const MagneticField *) const
void CosmicMuonTrajectoryBuilder::getDirectionByTime ( Trajectory traj) const
private

check the direction of trajectory by checking the timing

Definition at line 820 of file CosmicMuonTrajectoryBuilder.cc.

References category_, cschits_, dthits_, hfClusterShapes_cfi::hits, LogTrace, PV3DBase< T, PVType, FrameType >::perp(), and Trajectory::recHits().

820  {
822  LogTrace(category_) << "getDirectionByTime" << endl;
823  for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++) {
824  if (!(*ir)->isValid()) {
825  LogTrace(category_) << "invalid RecHit" << endl;
826  continue;
827  }
828 
829  const GlobalPoint& pos = (*ir)->globalPosition();
830  LogTrace(category_) << "pos" << pos << "radius " << pos.perp() << " dim " << (*ir)->dimension() << " det "
831  << (*ir)->det()->geographicalId().det() << " sub det " << (*ir)->det()->subDetector() << endl;
832 
833  if ((*ir)->det()->geographicalId().det() == 2 && (*ir)->det()->subDetector() == 6) {
834  // const CSCRecHit2D* iCSC = dynamic_cast<const CSCRecHit2D*>(&**ir);
835  // if (iCSC) LogTrace(category_)<<"csc from cast tpeak "<<iCSC->tpeak();
836  CSCRecHit2DCollection::range thisrange = cschits_->get(CSCDetId((*ir)->geographicalId()));
837  for (CSCRecHit2DCollection::const_iterator rechit = thisrange.first; rechit != thisrange.second; ++rechit) {
838  if ((*rechit).isValid())
839  LogTrace(category_) << "csc from collection tpeak " << (*rechit).tpeak();
840  }
841  }
842  if ((*ir)->det()->geographicalId().det() == 2 && (*ir)->det()->subDetector() == 7) {
843  // const DTRecHit1D* iDT = dynamic_cast<const DTRecHit1D*>(&**ir);
844  // if (iDT) LogTrace(category_)<<"dt digitime "<<iDT->digiTime();
845  DTRecHitCollection::range thisrange = dthits_->get(DTLayerId((*ir)->geographicalId()));
846  for (DTRecHitCollection::const_iterator rechit = thisrange.first; rechit != thisrange.second; ++rechit) {
847  if ((*rechit).isValid())
848  LogTrace(category_) << "dt from collection digitime " << (*rechit).digiTime();
849  }
850  }
851  }
852 
853  return;
854 }
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
T perp() const
Definition: PV3DBase.h:69
edm::Handle< CSCRecHit2DCollection > cschits_
ConstRecHitContainer recHits() const
Definition: Trajectory.h:186
edm::Handle< DTRecHitCollection > dthits_
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
#define LogTrace(id)
std::vector< ConstRecHitPointer > ConstRecHitContainer
void CosmicMuonTrajectoryBuilder::incrementChamberCounters ( const DetLayer layer,
int &  dtChambers,
int &  cscChambers,
int &  rpcChambers,
int &  totalChambers 
)
private

Definition at line 897 of file CosmicMuonTrajectoryBuilder.cc.

References GeomDetEnumerators::CSC, GeomDetEnumerators::DT, GeomDetEnumerators::RPCBarrel, GeomDetEnumerators::RPCEndcap, and DetLayer::subDetector().

Referenced by build(), and trajectories().

898  {
899  if (layer->subDetector() == GeomDetEnumerators::DT)
900  dtChambers++;
901  else if (layer->subDetector() == GeomDetEnumerators::CSC)
902  cscChambers++;
903  else if (layer->subDetector() == GeomDetEnumerators::RPCBarrel ||
905  rpcChambers++;
906  totalChambers++;
907 }
virtual SubDetector subDetector() const =0
The type of detector (PixelBarrel, PixelEndcap, TIB, TOB, TID, TEC, CSC, DT, RPCBarrel, RPCEndcap)
TrajectoryStateOnSurface CosmicMuonTrajectoryBuilder::intermediateState ( const TrajectoryStateOnSurface tsos) const
private

Definition at line 607 of file CosmicMuonTrajectoryBuilder.cc.

References category_, TrajectoryStateOnSurface::globalDirection(), LogTrace, Propagator::propagate(), and propagator().

Referenced by buildSecondHalf().

607  {
608  PerpendicularBoundPlaneBuilder planeBuilder;
609  GlobalPoint pos(0.0, 0.0, 0.0);
610  BoundPlane* SteppingPlane = planeBuilder(pos, tsos.globalDirection());
611 
612  TrajectoryStateOnSurface predTsos = propagator()->propagate(tsos, *SteppingPlane);
613  if (predTsos.isValid())
614  LogTrace(category_) << "intermediateState: a intermediate state: pos: " << predTsos.globalPosition()
615  << "mom: " << predTsos.globalMomentum();
616 
617  return predTsos;
618 }
const Propagator * propagator() const
#define LogTrace(id)
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
GlobalVector globalDirection() const
DirectMuonNavigation* CosmicMuonTrajectoryBuilder::navigation ( ) const
inline

Definition at line 72 of file CosmicMuonTrajectoryBuilder.h.

Referenced by build(), and trajectories().

72 { return theNavigation; }
const Propagator* CosmicMuonTrajectoryBuilder::propagator ( ) const
inline

Definition at line 57 of file CosmicMuonTrajectoryBuilder.h.

References HLT_FULL_cff::thePropagatorName.

Referenced by build(), intermediateState(), and trajectories().

edm::ESHandle< Propagator > propagator(std::string propagatorName) const
get the propagator
const Propagator* CosmicMuonTrajectoryBuilder::propagatorAlong ( ) const
inline

Definition at line 60 of file CosmicMuonTrajectoryBuilder.h.

Referenced by build().

60 { return &*theService->propagator("SteppingHelixPropagatorAlong"); }
edm::ESHandle< Propagator > propagator(std::string propagatorName) const
get the propagator
const Propagator* CosmicMuonTrajectoryBuilder::propagatorOpposite ( ) const
inline

Definition at line 62 of file CosmicMuonTrajectoryBuilder.h.

Referenced by build().

62 { return &*theService->propagator("SteppingHelixPropagatorOpposite"); }
edm::ESHandle< Propagator > propagator(std::string propagatorName) const
get the propagator
void CosmicMuonTrajectoryBuilder::reverseTrajectory ( Trajectory traj) const
private

reverse a trajectory without refit (out the measurements order changed)

Definition at line 707 of file CosmicMuonTrajectoryBuilder.cc.

References alongMomentum, Trajectory::firstMeasurement(), Trajectory::lastMeasurement(), Trajectory::measurements(), oppositeToMomentum, TrajectoryMeasurement::recHit(), and Trajectory::seed().

Referenced by buildSecondHalf().

707  {
708  PropagationDirection newDir =
709  (traj.firstMeasurement().recHit()->globalPosition().y() < traj.lastMeasurement().recHit()->globalPosition().y())
711  : alongMomentum;
712  Trajectory newTraj(traj.seed(), newDir);
713 
714  /* does not work in gcc4.8?)
715  std::vector<TrajectoryMeasurement> & meas = traj.measurements();
716  for (auto itm = meas.rbegin(); itm != meas.rend(); ++itm ) {
717  newTraj.push(std::move(*itm));
718  }
719  traj = std::move(newTraj);
720  */
721 
722  std::vector<TrajectoryMeasurement> const& meas = traj.measurements();
723  for (auto itm = meas.rbegin(); itm != meas.rend(); ++itm) {
724  newTraj.push(*itm);
725  }
726  traj = newTraj;
727 }
ConstRecHitPointer const & recHit() const
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:263
PropagationDirection
DataContainer const & measurements() const
Definition: Trajectory.h:178
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:150
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:166
void CosmicMuonTrajectoryBuilder::reverseTrajectoryPropagationDirection ( Trajectory traj) const
private

reverse the propagation direction of a trajectory

Definition at line 760 of file CosmicMuonTrajectoryBuilder.cc.

References alongMomentum, anyDirection, Trajectory::direction(), Trajectory::empty(), Trajectory::measurements(), oppositeToMomentum, Trajectory::pop(), and Trajectory::seed().

Referenced by trajectories().

760  {
761  if (traj.direction() == anyDirection)
762  return;
764  Trajectory newTraj(traj.seed(), newDir);
765  const std::vector<TrajectoryMeasurement>& meas = traj.measurements();
766 
767  for (std::vector<TrajectoryMeasurement>::const_iterator itm = meas.begin(); itm != meas.end(); ++itm) {
768  newTraj.push(*itm);
769  }
770 
771  while (!traj.empty()) {
772  traj.pop();
773  }
774 
775  traj = newTraj;
776 }
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:233
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:263
PropagationDirection
PropagationDirection const & direction() const
Definition: Trajectory.cc:133
DataContainer const & measurements() const
Definition: Trajectory.h:178
void pop()
Definition: Trajectory.cc:30
void CosmicMuonTrajectoryBuilder::selectHits ( MuonTransientTrackingRecHit::MuonRecHitContainer hits) const
private

Definition at line 623 of file CosmicMuonTrajectoryBuilder.cc.

References mps_fire::i, dqmiolumiharvest::j, keep, and createJobs::tmp.

623  {
624  if (hits.size() < 2)
625  return;
626 
628  vector<bool> keep(hits.size(), true);
629  int i(0);
630  int j(0);
631 
632  for (MuonRecHitContainer::const_iterator ihit = hits.begin(); ihit != hits.end(); ++ihit) {
633  if (!keep[i]) {
634  i++;
635  continue;
636  };
637  j = i + 1;
638  for (MuonRecHitContainer::const_iterator ihit2 = ihit + 1; ihit2 != hits.end(); ++ihit2) {
639  if (!keep[j]) {
640  j++;
641  continue;
642  }
643  if ((*ihit)->geographicalId() == (*ihit2)->geographicalId()) {
644  if ((*ihit)->dimension() > (*ihit2)->dimension()) {
645  keep[j] = false;
646  } else if ((*ihit)->dimension() < (*ihit2)->dimension()) {
647  keep[i] = false;
648  } else {
649  if ((*ihit)->transientHits().size() > (*ihit2)->transientHits().size()) {
650  keep[j] = false;
651  } else if ((*ihit)->transientHits().size() < (*ihit2)->transientHits().size()) {
652  keep[i] = false;
653  } else if ((*ihit)->degreesOfFreedom() != 0 && (*ihit2)->degreesOfFreedom() != 0) {
654  if (((*ihit)->chi2() / (*ihit)->degreesOfFreedom()) > ((*ihit2)->chi2() / (*ihit)->degreesOfFreedom()))
655  keep[i] = false;
656  else
657  keep[j] = false;
658  }
659  }
660  } // if same geomid
661  j++;
662  }
663  i++;
664  }
665 
666  i = 0;
667  for (MuonRecHitContainer::const_iterator ihit = hits.begin(); ihit != hits.end(); ++ihit) {
668  if (keep[i])
669  tmp.push_back(*ihit);
670  i++;
671  }
672 
673  hits.clear();
674  hits.swap(tmp);
675 
676  return;
677 }
const int keep
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
tmp
align.sh
Definition: createJobs.py:716
bool CosmicMuonTrajectoryBuilder::selfDuplicate ( const Trajectory traj) const
private

check if the trajectory iterates the same hit more than once

Definition at line 682 of file CosmicMuonTrajectoryBuilder.cc.

References Trajectory::empty(), hfClusterShapes_cfi::hits, Trajectory::recHits(), and mps_fire::result.

Referenced by trajectories().

682  {
684 
685  if (traj.empty())
686  return true;
687 
688  bool result = false;
689  for (ConstRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++) {
690  if (!(*ir)->isValid())
691  continue;
692  for (ConstRecHitContainer::const_iterator ir2 = ir + 1; ir2 != hits.end(); ir2++) {
693  if (!(*ir2)->isValid())
694  continue;
695  if ((*ir) == (*ir2))
696  result = true;
697  }
698  }
699 
700  return result;
701 }
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:233
ConstRecHitContainer recHits() const
Definition: Trajectory.h:186
std::vector< ConstRecHitPointer > ConstRecHitContainer
void CosmicMuonTrajectoryBuilder::setEvent ( const edm::Event event)
overridevirtual

pass the Event to the algo at each event

Implements MuonTrajectoryBuilder.

Definition at line 121 of file CosmicMuonTrajectoryBuilder.cc.

References category_, LogTrace, MuonDetLayerMeasurements::setEvent(), theCacheId_DG, theLayerMeasurements, theNavigation, theNavigationPSet, and theService.

121  {
123 
124  // DetLayer Geometry
125  unsigned long long newCacheId_DG = theService->eventSetup().get<MuonRecoGeometryRecord>().cacheIdentifier();
126  if (newCacheId_DG != theCacheId_DG) {
127  LogTrace(category_) << "Muon Reco Geometry changed!";
128  theCacheId_DG = newCacheId_DG;
129  if (theNavigation)
130  delete theNavigation;
132  }
133 }
MuonDetLayerMeasurements * theLayerMeasurements
#define LogTrace(id)
void setEvent(const edm::Event &)
set event
CosmicMuonSmoother* CosmicMuonTrajectoryBuilder::smoother ( ) const
inline

Definition at line 68 of file CosmicMuonTrajectoryBuilder.h.

68 { return theSmoother; }
double CosmicMuonTrajectoryBuilder::t0 ( const DTRecSegment4D deseg) const

Definition at line 912 of file CosmicMuonTrajectoryBuilder.cc.

References category_, DTRecSegment4D::hasPhi(), DTRecSegment2D::ist0Valid(), LogTrace, DTRecSegment4D::phiSegment(), mps_fire::result, DTRecSegment2D::specificRecHits(), and DTRecSegment2D::t0().

Referenced by checkDirectionByT0().

912  {
913  if ((dtseg == nullptr) || (!dtseg->hasPhi()))
914  return 0;
915  // timing information
916  double result = 0;
917  if (dtseg->phiSegment() == nullptr)
918  return 0;
919  int phiHits = dtseg->phiSegment()->specificRecHits().size();
920  LogTrace(category_) << "phiHits " << phiHits;
921  if (phiHits > 5) {
922  if (dtseg->phiSegment()->ist0Valid())
923  result = dtseg->phiSegment()->t0();
924  if (dtseg->phiSegment()->ist0Valid()) {
925  LogTrace(category_) << " Phi t0: " << dtseg->phiSegment()->t0() << " hits: " << phiHits;
926  } else {
927  LogTrace(category_) << " Phi t0 is invalid: " << dtseg->phiSegment()->t0() << " hits: " << phiHits;
928  }
929  }
930 
931  return result;
932 }
#define LogTrace(id)
MuonTrajectoryBuilder::TrajectoryContainer CosmicMuonTrajectoryBuilder::trajectories ( const TrajectorySeed seed)
overridevirtual

build trajectories from seed

Implements MuonTrajectoryBuilder.

Definition at line 135 of file CosmicMuonTrajectoryBuilder.cc.

References alongMomentum, backwardUpdator(), PV3DBase< T, PVType, FrameType >::basicVector(), buildSecondHalf(), category_, Trajectory::chiSquared(), DirectMuonNavigation::compatibleEndcapLayers(), DirectMuonNavigation::compatibleLayers(), MuonSubdetId::CSC, debug, DeadROC_duringRun::dir, Trajectory::direction(), Basic3DVector< T >::dot(), MuonSubdetId::DT, Trajectory::empty(), GeomDetEnumerators::endcap, estimateDirection(), MuonTrajectoryUpdator::estimator(), PV3DBase< T, PVType, FrameType >::eta(), findBestMeasurements(), Trajectory::firstMeasurement(), flipTrajectory(), TrajectoryStateOnSurface::freeState(), TrajectoryStateOnSurface::globalMomentum(), TrajectoryStateOnSurface::globalPosition(), incrementChamberCounters(), insideOut, TrajectoryStateOnSurface::isValid(), Trajectory::isValid(), Trajectory::lastMeasurement(), LogTrace, PV3DBase< T, PVType, FrameType >::mag(), Trajectory::measurements(), navigation(), oppositeToMomentum, outsideIn, Trajectory::pop(), propagator(), MuonDetLayerMeasurements::recHits(), TrajectoryStateOnSurface::rescaleError(), mps_fire::result, groupFilesInBlocks::reverse, reverseTrajectoryPropagationDirection(), selfDuplicate(), MuonTrajectoryUpdator::setFitDirection(), TrajectorySeed::startingState(), OrderedSet::t, theBKUpdator, theLayerMeasurements, theService, theSmoother, theStrict1LegFlag, theTraversingMuonFlag, CosmicMuonSmoother::trajectories(), trajectoryStateTransform::transientState(), unusedHits(), MuonTrajectoryUpdator::update(), TrajectoryMeasurement::updatedState(), updator(), utilities(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

135  {
136  vector<Trajectory*> trajL = vector<Trajectory*>();
137 
139 
140  PTrajectoryStateOnDet ptsd1(seed.startingState());
141  DetId did(ptsd1.detId());
142  const BoundPlane& bp = theService->trackingGeometry()->idToDet(did)->surface();
143  TrajectoryStateOnSurface lastTsos =
144  trajectoryStateTransform::transientState(ptsd1, &bp, &*theService->magneticField());
145  LogTrace(category_) << "Seed: mom " << lastTsos.globalMomentum() << "pos: " << lastTsos.globalPosition();
146  LogTrace(category_) << "Seed: mom eta " << lastTsos.globalMomentum().eta()
147  << "pos eta: " << lastTsos.globalPosition().eta();
148 
149  bool beamhaloFlag = ((did.subdetId() == MuonSubdetId::CSC) && fabs(lastTsos.globalMomentum().eta()) > 4.0);
150 
151  vector<const DetLayer*> navLayers;
152 
153  if (did.subdetId() == MuonSubdetId::DT) {
154  //DT
155  navLayers = navigation()->compatibleLayers(*(lastTsos.freeState()), alongMomentum);
156  } else if (beamhaloFlag || (theTraversingMuonFlag && theStrict1LegFlag)) {
157  //CSC
158  navLayers = navigation()->compatibleEndcapLayers(*(lastTsos.freeState()), alongMomentum);
159  } else {
160  navLayers = navigation()->compatibleLayers(*(lastTsos.freeState()), alongMomentum);
161  }
162 
163  LogTrace(category_) << "found " << navLayers.size() << " compatible DetLayers for the Seed";
164 
165  if (navLayers.empty())
166  return trajL;
167 
168  vector<DetWithState> detsWithStates;
169  LogTrace(category_) << "Compatible layers: ";
170  for (vector<const DetLayer*>::const_iterator layer = navLayers.begin(); layer != navLayers.end(); layer++) {
171  LogTrace(category_) << debug.dumpMuonId((*layer)->basicComponents().front()->geographicalId())
172  << debug.dumpLayer(*layer);
173  }
174 
175  detsWithStates = navLayers.front()->compatibleDets(lastTsos, *propagator(), *(updator()->estimator()));
176  LogTrace(category_) << "Number of compatible dets: " << detsWithStates.size() << endl;
177 
178  if (!detsWithStates.empty()) {
179  // get the updated TSOS
180  if (detsWithStates.front().second.isValid()) {
181  LogTrace(category_) << "New starting TSOS is on det: " << endl;
182  LogTrace(category_) << debug.dumpMuonId(detsWithStates.front().first->geographicalId())
183  << debug.dumpLayer(navLayers.front());
184  lastTsos = detsWithStates.front().second;
185  LogTrace(category_) << "Seed after extrapolation: mom " << lastTsos.globalMomentum()
186  << "pos: " << lastTsos.globalPosition();
187  }
188  }
189  detsWithStates.clear();
190  if (!lastTsos.isValid())
191  return trajL;
192 
193  TrajectoryStateOnSurface secondLast = lastTsos;
194 
195  lastTsos.rescaleError(10.0);
196 
197  Trajectory* theTraj = new Trajectory(seed, alongMomentum);
198 
199  navLayers.clear();
200 
201  if (fabs(lastTsos.globalMomentum().eta()) < 1.0) {
202  //DT
203  navLayers = navigation()->compatibleLayers(*(lastTsos.freeState()), alongMomentum);
204  } else if (beamhaloFlag || (theTraversingMuonFlag && theStrict1LegFlag)) {
205  //CSC
206  navLayers = navigation()->compatibleEndcapLayers(*(lastTsos.freeState()), alongMomentum);
207  } else {
208  navLayers = navigation()->compatibleLayers(*(lastTsos.freeState()), alongMomentum);
209  }
210 
211  int DTChamberUsedBack = 0;
212  int CSCChamberUsedBack = 0;
213  int RPCChamberUsedBack = 0;
214  int TotalChamberUsedBack = 0;
216  vector<TrajectoryMeasurement> measL;
217 
218  LogTrace(category_) << "Begin forward fit " << navLayers.size();
219 
220  for (vector<const DetLayer*>::const_iterator rnxtlayer = navLayers.begin(); rnxtlayer != navLayers.end();
221  ++rnxtlayer) {
222  LogTrace(category_) << "new layer ";
223  measL.clear();
224  LogTrace(category_) << debug.dumpMuonId((*rnxtlayer)->basicComponents().front()->geographicalId())
225  << debug.dumpLayer(*rnxtlayer);
226  LogTrace(category_) << "from lastTsos " << lastTsos.globalMomentum() << " at " << lastTsos.globalPosition();
227 
228  measL = findBestMeasurements(*rnxtlayer, lastTsos, propagator(), (updator()->estimator()));
229 
230  if (measL.empty() && (fabs(theService->magneticField()->inTesla(GlobalPoint(0, 0, 0)).z()) < 0.01) &&
231  (theService->propagator("StraightLinePropagator").isValid())) {
232  LogTrace(category_) << "try straight line propagator ";
233  measL = findBestMeasurements(
234  *rnxtlayer, lastTsos, &*theService->propagator("StraightLinePropagator"), (updator()->estimator()));
235  }
236  if (measL.empty())
237  continue;
238 
239  for (vector<TrajectoryMeasurement>::const_iterator theMeas = measL.begin(); theMeas != measL.end(); ++theMeas) {
240  pair<bool, TrajectoryStateOnSurface> result = updator()->update((&*theMeas), *theTraj, propagator());
241 
242  if (result.first) {
243  LogTrace(category_) << "update ok ";
245  (*rnxtlayer), DTChamberUsedBack, CSCChamberUsedBack, RPCChamberUsedBack, TotalChamberUsedBack);
246  secondLast = lastTsos;
247  if ((!theTraj->empty()) && result.second.isValid()) {
248  lastTsos = result.second;
249  LogTrace(category_) << "get new lastTsos here " << lastTsos.globalMomentum() << " at "
250  << lastTsos.globalPosition();
251  } else if ((theMeas)->predictedState().isValid())
252  lastTsos = (theMeas)->predictedState();
253  }
254  }
255  }
256  measL.clear();
257  while (!theTraj->empty()) {
258  theTraj->pop();
259  }
260 
261  if (!theTraj->isValid() || TotalChamberUsedBack < 2 || (DTChamberUsedBack + CSCChamberUsedBack) == 0 ||
262  !lastTsos.isValid()) {
263  delete theTraj;
264  return trajL;
265  }
266  delete theTraj;
267 
268  // if got good trajectory, then do backward refitting
269  DTChamberUsedBack = 0;
270  CSCChamberUsedBack = 0;
271  RPCChamberUsedBack = 0;
272  TotalChamberUsedBack = 0;
273 
274  Trajectory myTraj(seed, oppositeToMomentum);
275 
276  // set starting navigation direction for MuonTrajectoryUpdator
277 
278  GlobalPoint lastPos = lastTsos.globalPosition();
279  GlobalPoint secondLastPos = secondLast.globalPosition();
280  GlobalVector momDir = secondLastPos - lastPos;
281 
282  if (lastPos.basicVector().dot(momDir.basicVector()) > 0) {
283  // LogTrace("CosmicMuonTrajectoryBuilder")<<"Fit direction changed to insideOut";
285  } else
287 
288  if (fabs(lastTsos.globalMomentum().eta()) < 1.0) {
289  //DT
290  navLayers = navigation()->compatibleLayers(*(lastTsos.freeState()), oppositeToMomentum);
291  } else if (beamhaloFlag || (theTraversingMuonFlag && theStrict1LegFlag)) {
292  //CSC
293  std::reverse(navLayers.begin(), navLayers.end());
294  } else {
295  navLayers = navigation()->compatibleLayers(*(lastTsos.freeState()), oppositeToMomentum);
296  }
297 
298  LogTrace(category_) << "Begin backward refitting, with " << navLayers.size() << " layers" << endl;
299 
300  for (vector<const DetLayer*>::const_iterator rnxtlayer = navLayers.begin(); rnxtlayer != navLayers.end();
301  ++rnxtlayer) {
302  measL.clear();
303 
304  measL = findBestMeasurements(*rnxtlayer, lastTsos, propagator(), (backwardUpdator()->estimator()));
305 
306  if (measL.empty()) {
308  for (MuonRecHitContainer::const_iterator ihit = tmpHits.begin(); ihit != tmpHits.end(); ++ihit) {
309  allUnusedHits.push_back(*ihit);
310  }
311  continue;
312  }
313 
314  for (vector<TrajectoryMeasurement>::const_iterator theMeas = measL.begin(); theMeas != measL.end(); ++theMeas) {
315  // if the part change, we need to reconsider the fit direction
316  if (rnxtlayer != navLayers.begin()) {
317  vector<const DetLayer*>::const_iterator lastlayer = rnxtlayer;
318  lastlayer--;
319 
320  if ((*rnxtlayer)->location() != (*lastlayer)->location()) {
321  lastPos = lastTsos.globalPosition();
322  GlobalPoint thisPos = (theMeas)->predictedState().globalPosition();
323  GlobalVector momDir = thisPos - lastPos;
324  // LogTrace("CosmicMuonTrajectoryBuilder")<<"momDir "<<momDir;
325 
326  if (momDir.mag() > 0.01) { //if lastTsos is on the surface, no need
327  if (thisPos.basicVector().dot(momDir.basicVector()) > 0) {
329  } else
331  }
332  }
333  if (((*lastlayer)->location() == GeomDetEnumerators::endcap) &&
334  ((*rnxtlayer)->location() == GeomDetEnumerators::endcap) &&
335  (lastTsos.globalPosition().z() * (theMeas)->predictedState().globalPosition().z() < 0)) {
337  }
338  }
339 
340  // if (theBKUpdator->fitDirection() == insideOut)
341  // LogTrace("CosmicMuonTrajectoryBuilder")<<"Fit direction insideOut";
342  // else LogTrace("CosmicMuonTrajectoryBuilder")<<"Fit direction outsideIn";
343  pair<bool, TrajectoryStateOnSurface> bkresult = backwardUpdator()->update((&*theMeas), myTraj, propagator());
344 
345  if (bkresult.first) {
347  (*rnxtlayer), DTChamberUsedBack, CSCChamberUsedBack, RPCChamberUsedBack, TotalChamberUsedBack);
348 
349  if (theTraversingMuonFlag) {
350  MuonRecHitContainer tmpUnusedHits = unusedHits(*rnxtlayer, *theMeas);
351  allUnusedHits.insert(allUnusedHits.end(), tmpUnusedHits.begin(), tmpUnusedHits.end());
352  }
353  if ((!myTraj.empty()) && bkresult.second.isValid())
354  lastTsos = bkresult.second;
355  else if ((theMeas)->predictedState().isValid())
356  lastTsos = (theMeas)->predictedState();
357  }
358  }
359  }
360 
361  for (vector<Trajectory*>::iterator t = trajL.begin(); t != trajL.end(); ++t)
362  delete *t;
363 
364  trajL.clear();
365 
366  if ((!myTraj.isValid()) || (myTraj.empty()) || ((selfDuplicate(myTraj))) || TotalChamberUsedBack < 2 ||
367  (DTChamberUsedBack + CSCChamberUsedBack) < 1) {
368  return trajL;
369  }
370 
371  if (theTraversingMuonFlag && (allUnusedHits.size() >= 2)) {
372  // LogTrace(category_)<<utilities()->print(allUnusedHits);
373  LogTrace(category_) << "Building trajectory in second hemisphere...";
374  buildSecondHalf(myTraj);
375  // check if traversing trajectory has hits in both hemispheres
376 
377  if (theStrict1LegFlag && !utilities()->isTraversing(myTraj)) {
378  trajL.clear();
379  return trajL;
380  }
382  trajL.clear();
383  return trajL;
384  }
385 
386  LogTrace(category_) << " traj ok ";
387 
388  // getDirectionByTime(myTraj);
389  if (beamhaloFlag)
390  estimateDirection(myTraj);
391  if (myTraj.empty())
392  return trajL;
393 
394  // try to smooth it
395  vector<Trajectory> smoothed = theSmoother->trajectories(myTraj);
396 
397  if (!smoothed.empty() && smoothed.front().foundHits() > 3) {
398  LogTrace(category_) << " Smoothed successfully.";
399  myTraj = smoothed.front();
400  } else {
401  LogTrace(category_) << " Smooth failed.";
402  }
403 
404  LogTrace(category_) << "first " << myTraj.firstMeasurement().updatedState() << "\n last "
405  << myTraj.lastMeasurement().updatedState();
406  if (myTraj.direction() == alongMomentum)
407  LogTrace(category_) << "alongMomentum";
408  else if (myTraj.direction() == oppositeToMomentum)
409  LogTrace(category_) << "oppositeMomentum";
410  else
411  LogTrace(category_) << "anyDirection";
412 
413  if (!beamhaloFlag) {
414  if (myTraj.lastMeasurement().updatedState().globalMomentum().y() > 0) {
415  LogTrace(category_) << "flip trajectory ";
416  flipTrajectory(myTraj);
417  }
418 
419  if ((myTraj.direction() == alongMomentum && (myTraj.firstMeasurement().updatedState().globalPosition().y() <
420  myTraj.lastMeasurement().updatedState().globalPosition().y())) ||
421  (myTraj.direction() == oppositeToMomentum && (myTraj.firstMeasurement().updatedState().globalPosition().y() >
422  myTraj.lastMeasurement().updatedState().globalPosition().y()))) {
423  LogTrace(category_) << "reverse propagation direction";
425  }
426  }
427  // getDirectionByTime(myTraj);
428  if (!myTraj.isValid())
429  return trajL;
430 
431  // check direction agree with position!
432  PropagationDirection dir = myTraj.direction();
433  GlobalVector dirFromPos = myTraj.measurements().back().recHit()->globalPosition() -
434  myTraj.measurements().front().recHit()->globalPosition();
435 
436  if (theStrict1LegFlag && !utilities()->isTraversing(myTraj)) {
437  trajL.clear();
438  return trajL;
439  }
440 
441  LogTrace(category_) << "last hit " << myTraj.measurements().back().recHit()->globalPosition() << endl;
442  LogTrace(category_) << "first hit " << myTraj.measurements().front().recHit()->globalPosition() << endl;
443 
444  LogTrace(category_) << "last tsos " << myTraj.measurements().back().updatedState().globalPosition() << " mom "
445  << myTraj.measurements().back().updatedState().globalMomentum() << endl;
446  LogTrace(category_) << "first tsos " << myTraj.measurements().front().updatedState().globalPosition() << " mom "
447  << myTraj.measurements().front().updatedState().globalMomentum() << endl;
448 
449  PropagationDirection propDir =
450  (dirFromPos.basicVector().dot(myTraj.firstMeasurement().updatedState().globalMomentum().basicVector()) > 0)
451  ? alongMomentum
453  LogTrace(category_) << " dir " << dir << " propDir " << propDir << endl;
454 
455  LogTrace(category_) << "chi2 " << myTraj.chiSquared() << endl;
456 
457  if (dir != propDir) {
458  LogTrace(category_) << "reverse propagation direction ";
460  }
461  if (myTraj.empty())
462  return trajL;
463 
464  trajL.push_back(new Trajectory(myTraj));
465  navLayers.clear();
466  return trajL;
467 }
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:233
void reverseTrajectoryPropagationDirection(Trajectory &) const
reverse the propagation direction of a trajectory
const Propagator * propagator() const
const MeasurementEstimator * estimator() const
accasso at the propagator
std::vector< const DetLayer * > compatibleEndcapLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection) const
void estimateDirection(Trajectory &) const
check the direction of trajectory by checking eta spread
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
MuonTrajectoryUpdator * backwardUpdator() const
GlobalPoint globalPosition() const
PropagationDirection
MuonDetLayerMeasurements * theLayerMeasurements
const CosmicMuonUtilities * utilities() const
std::vector< const DetLayer * > compatibleLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection) const
DirectMuonNavigation * navigation() const
T mag() const
Definition: PV3DBase.h:64
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 setFitDirection(NavigationDirection fitDirection)
set fit direction
FreeTrajectoryState const * freeState(bool withErrors=true) const
T z() const
Definition: PV3DBase.h:61
void incrementChamberCounters(const DetLayer *layer, int &dtChambers, int &cscChambers, int &rpcChambers, int &totalChambers)
#define LogTrace(id)
Definition: DetId.h:17
bool isValid() const
Definition: Trajectory.h:257
PTrajectoryStateOnDet const & startingState() const
#define debug
Definition: HDRShower.cc:19
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
void pop()
Definition: Trajectory.cc:30
T eta() const
Definition: PV3DBase.h:73
GlobalVector globalMomentum() 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
bool selfDuplicate(const Trajectory &) const
check if the trajectory iterates the same hit more than once
static constexpr int DT
Definition: MuonSubdetId.h:11
MuonTransientTrackingRecHit::MuonRecHitContainer unusedHits(const DetLayer *, const TrajectoryMeasurement &) const
static constexpr int CSC
Definition: MuonSubdetId.h:12
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
std::vector< MuonRecHitPointer > MuonRecHitContainer
TrajectoryContainer trajectories(const Trajectory &traj) const override
T dot(const Basic3DVector &rh) const
Scalar product, or "dot" product, with a vector of same type.
CandidateContainer CosmicMuonTrajectoryBuilder::trajectories ( const TrackCand )
inlineoverridevirtual

dummy implementation, unused in this class

Implements MuonTrajectoryBuilder.

Definition at line 53 of file CosmicMuonTrajectoryBuilder.h.

53 { return CandidateContainer(); }
MuonCandidate::CandidateContainer CandidateContainer
MuonTransientTrackingRecHit::MuonRecHitContainer CosmicMuonTrajectoryBuilder::unusedHits ( const DetLayer layer,
const TrajectoryMeasurement meas 
) const
private

Definition at line 472 of file CosmicMuonTrajectoryBuilder.cc.

References category_, LogTrace, TrajectoryMeasurement::recHit(), MuonDetLayerMeasurements::recHits(), mps_fire::result, and theLayerMeasurements.

Referenced by trajectories().

473  {
476  for (MuonRecHitContainer::const_iterator ihit = tmpHits.begin(); ihit != tmpHits.end(); ++ihit) {
477  if ((*ihit)->geographicalId() != meas.recHit()->geographicalId()) {
478  result.push_back(*ihit);
479  LogTrace(category_) << "Unused hit: " << (*ihit)->globalPosition() << endl;
480  }
481  }
482 
483  return result;
484 }
ConstRecHitPointer const & recHit() const
MuonDetLayerMeasurements * theLayerMeasurements
MuonRecHitContainer recHits(const DetLayer *layer, const edm::Event &iEvent)
returns the rechits which are on the layer
#define LogTrace(id)
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
std::vector< MuonRecHitPointer > MuonRecHitContainer
MuonTrajectoryUpdator* CosmicMuonTrajectoryBuilder::updator ( ) const
inline

Definition at line 64 of file CosmicMuonTrajectoryBuilder.h.

Referenced by build(), and trajectories().

64 { return theUpdator; }
const CosmicMuonUtilities* CosmicMuonTrajectoryBuilder::utilities ( ) const
inline

Definition at line 70 of file CosmicMuonTrajectoryBuilder.h.

Referenced by estimateDirection(), flipTrajectory(), and trajectories().

70 { return smoother()->utilities(); }
CosmicMuonSmoother * smoother() const
const CosmicMuonUtilities * utilities() const

Member Data Documentation

std::string CosmicMuonTrajectoryBuilder::category_
private
edm::Handle<CSCRecHit2DCollection> CosmicMuonTrajectoryBuilder::cschits_
private

Definition at line 139 of file CosmicMuonTrajectoryBuilder.h.

Referenced by getDirectionByTime().

edm::Handle<DTRecHitCollection> CosmicMuonTrajectoryBuilder::dthits_
private

Definition at line 140 of file CosmicMuonTrajectoryBuilder.h.

Referenced by getDirectionByTime().

MuonBestMeasurementFinder* CosmicMuonTrajectoryBuilder::theBestMeasurementFinder
private
MuonTrajectoryUpdator* CosmicMuonTrajectoryBuilder::theBKUpdator
private
unsigned long long CosmicMuonTrajectoryBuilder::theCacheId_DG
private

Definition at line 138 of file CosmicMuonTrajectoryBuilder.h.

Referenced by CosmicMuonTrajectoryBuilder(), and setEvent().

MuonDetLayerMeasurements* CosmicMuonTrajectoryBuilder::theLayerMeasurements
private
DirectMuonNavigation* CosmicMuonTrajectoryBuilder::theNavigation
private
edm::ParameterSet CosmicMuonTrajectoryBuilder::theNavigationPSet
private

Definition at line 118 of file CosmicMuonTrajectoryBuilder.h.

Referenced by CosmicMuonTrajectoryBuilder(), and setEvent().

int CosmicMuonTrajectoryBuilder::theNSuccess
private
int CosmicMuonTrajectoryBuilder::theNTraversing
private
std::string CosmicMuonTrajectoryBuilder::thePropagatorName
private

Definition at line 129 of file CosmicMuonTrajectoryBuilder.h.

Referenced by CosmicMuonTrajectoryBuilder().

const MuonServiceProxy* CosmicMuonTrajectoryBuilder::theService
private
CosmicMuonSmoother* CosmicMuonTrajectoryBuilder::theSmoother
private
bool CosmicMuonTrajectoryBuilder::theStrict1LegFlag
private

Definition at line 132 of file CosmicMuonTrajectoryBuilder.h.

Referenced by build(), CosmicMuonTrajectoryBuilder(), and trajectories().

bool CosmicMuonTrajectoryBuilder::theTraversingMuonFlag
private

Definition at line 131 of file CosmicMuonTrajectoryBuilder.h.

Referenced by build(), CosmicMuonTrajectoryBuilder(), and trajectories().

MuonTrajectoryUpdator* CosmicMuonTrajectoryBuilder::theUpdator
private