test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
 
virtual void setEvent (const edm::Event &)
 pass the Event to the algo at each event More...
 
CosmicMuonSmoothersmoother () const
 
double t0 (const DTRecSegment4D *deseg) const
 
std::vector< Trajectory * > trajectories (const TrajectorySeed &)
 build trajectories from seed More...
 
virtual CandidateContainer trajectories (const TrackCand &)
 dummy implementation, unused in this class More...
 
MuonTrajectoryUpdatorupdator () const
 
const CosmicMuonUtilitiesutilities () const
 
virtual ~CosmicMuonTrajectoryBuilder ()
 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
< TrajectoryMeasurement
findBestMeasurements (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
< CSCRecHit2DCollection
cschits_
 
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::TrackRef
TrackCand
 
typedef
MuonCandidate::TrajectoryContainer 
TrajectoryContainer
 

Detailed Description

Definition at line 38 of file CosmicMuonTrajectoryBuilder.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 44 of file CosmicMuonTrajectoryBuilder.cc.

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

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

Destructor.

Definition at line 102 of file CosmicMuonTrajectoryBuilder.cc.

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

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

Member Function Documentation

MuonTrajectoryUpdator* CosmicMuonTrajectoryBuilder::backwardUpdator ( ) const
inline

Definition at line 67 of file CosmicMuonTrajectoryBuilder.h.

References theBKUpdator.

Referenced by build(), and trajectories().

67 {return theBKUpdator;}
MuonBestMeasurementFinder* CosmicMuonTrajectoryBuilder::bestMeasurementFinder ( ) const
inline

Definition at line 75 of file CosmicMuonTrajectoryBuilder.h.

References theBestMeasurementFinder.

MuonBestMeasurementFinder * theBestMeasurementFinder
void CosmicMuonTrajectoryBuilder::build ( const TrajectoryStateOnSurface ts,
const NavigationDirection startingDir,
Trajectory traj 
)
private

Definition at line 474 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by buildSecondHalf().

476  {
477 
478  if ( !ts.isValid() ) return;
479 
480  const FreeTrajectoryState* fts = ts.freeState();
481  if ( !fts ) return;
482 
483  vector<const DetLayer*> navLayers;
484 
485  if (fabs(fts->momentum().basicVector().eta()) < 1.0) {
486  //DT
487  if (fts->position().basicVector().dot(fts->momentum().basicVector())>0){
488  navLayers = navigation()->compatibleLayers((*fts), alongMomentum);
489  } else {
490  navLayers = navigation()->compatibleLayers((*fts), oppositeToMomentum);
491  }
492 
494  //CSC
495  if (fts->position().basicVector().dot(fts->momentum().basicVector())>0){
496  navLayers = navigation()->compatibleEndcapLayers((*fts), alongMomentum);
497  } else {
498  navLayers = navigation()->compatibleEndcapLayers((*fts), oppositeToMomentum);
499  }
500  } else {
501 
502  if (fts->position().basicVector().dot(fts->momentum().basicVector())>0){
503  navLayers = navigation()->compatibleLayers((*fts), alongMomentum);
504  } else {
505  navLayers = navigation()->compatibleLayers((*fts), oppositeToMomentum);
506  }
507 
508 }
509 
510  if (navLayers.empty()) return;
511 
512  theBKUpdator->setFitDirection(startingDir);
513 
514  int DTChamberUsedBack = 0;
515  int CSCChamberUsedBack = 0;
516  int RPCChamberUsedBack = 0;
517  int TotalChamberUsedBack = 0;
518 
519  TrajectoryStateOnSurface lastTsos =
522  propagatorAlong()->propagate((*fts),navLayers.front()->surface()) : propagatorOpposite()->propagate((*fts),navLayers.front()->surface());
523 
524  if ( !lastTsos.isValid() ) {
525  LogTrace(category_)<<"propagation failed from fts to inner cylinder";
526  return;
527  }
528  LogTrace(category_)<<"tsos "<<lastTsos.globalPosition();
529  lastTsos.rescaleError(10.);
530  vector<TrajectoryMeasurement> measL;
531  for (vector<const DetLayer*>::const_iterator rnxtlayer = navLayers.begin();
532  rnxtlayer!= navLayers.end(); ++rnxtlayer) {
533 
534  measL.clear();
535  measL = findBestMeasurements(*rnxtlayer, lastTsos, propagator(), (backwardUpdator()->estimator()));
536 
537  if ( measL.empty() ) continue;
538 
539  for (vector<TrajectoryMeasurement>::const_iterator theMeas = measL.begin(); theMeas != measL.end(); ++theMeas) {
540 
541  pair<bool,TrajectoryStateOnSurface> bkresult
542  = backwardUpdator()->update((&*theMeas), traj, propagator());
543  if (bkresult.first ) {
544  LogTrace(category_)<<"update ok : "<<(theMeas)->recHit()->globalPosition() ;
545 
546  incrementChamberCounters((*rnxtlayer), DTChamberUsedBack, CSCChamberUsedBack, RPCChamberUsedBack, TotalChamberUsedBack);
547 
548  if ( (!traj.empty()) && bkresult.second.isValid() )
549  lastTsos = bkresult.second;
550  else if ((theMeas)->predictedState().isValid())
551  lastTsos = (theMeas)->predictedState();
552  }
553  }
554  }
555  navLayers.clear();
556  updator()->makeFirstTime();
558 
559  measL.clear();
560 
561  return;
562 
563 }
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:244
const Propagator * propagator() const
virtual FreeTrajectoryState propagate(const FreeTrajectoryState &ftsStart, const GlobalPoint &pDest) const final
Definition: Propagator.h:119
std::vector< const DetLayer * > compatibleEndcapLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection) const
void makeFirstTime()
reset the theFirstTSOSFlag
T y() const
Definition: PV3DBase.h:63
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:181
FreeTrajectoryState const * freeState(bool withErrors=true) const
if(c.getParameter< edm::InputTag >("puppiValueMap").label().size()!=0)
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:194
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:56
T dot(const Basic3DVector &rh) const
Scalar product, or &quot;dot&quot; product, with a vector of same type.
void CosmicMuonTrajectoryBuilder::buildSecondHalf ( Trajectory traj)
private

Definition at line 570 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().

570  {
571 
572  if ( (traj.firstMeasurement().recHit()->globalPosition().perp()
573  < traj.lastMeasurement().recHit()->globalPosition().perp()) ) {
574  LogTrace(category_)<<"inside-out: reverseTrajectory";
575  reverseTrajectory(traj);
576  }
577  if (traj.empty()) return;
579  if ( !tsos.isValid() ) tsos = traj.lastMeasurement().predictedState();
580  LogTrace(category_)<<"last tsos on traj: pos: "<< tsos.globalPosition()<<" mom: "<< tsos.globalMomentum();
581  if ( !tsos.isValid() ) {
582  LogTrace(category_)<<"last tsos on traj invalid";
583  return;
584  }
585 
586  build(intermediateState(tsos),insideOut,traj);
587 
588  return;
589 
590 }
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:244
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:181
#define LogTrace(id)
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:194
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 945 of file CosmicMuonTrajectoryBuilder.cc.

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

946  {
947 
948  LogTrace(category_) << "comparing dtseg: " << dtseg1 << " " << dtseg2 << endl;
949  if (dtseg1 == dtseg2 || t0(dtseg1) == t0(dtseg2)) return anyDirection;
950 
952  ( t0(dtseg1) < t0(dtseg2) ) ? alongMomentum : oppositeToMomentum;
953 
954  return result;
955 
956 }
double t0(const DTRecSegment4D *deseg) const
PropagationDirection
tuple result
Definition: query.py:137
#define LogTrace(id)
void CosmicMuonTrajectoryBuilder::estimateDirection ( Trajectory traj) const
private

check the direction of trajectory by checking eta spread

Definition at line 776 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by trajectories().

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

Definition at line 864 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by build(), and trajectories().

867  {
868 
869  std::vector<TrajectoryMeasurement> result;
870  std::vector<TrajectoryMeasurement> measurements;
871 
872  if ( layer->hasGroups() ) {
873  std::vector<TrajectoryMeasurementGroup> measurementGroups =
874  theLayerMeasurements->groupedMeasurements(layer, tsos, *propagator, *estimator);
875 
876  for (std::vector<TrajectoryMeasurementGroup>::const_iterator tmGroupItr = measurementGroups.begin();
877  tmGroupItr != measurementGroups.end(); ++tmGroupItr) {
878 
879  measurements = tmGroupItr->measurements();
880  const TrajectoryMeasurement* bestMeasurement
881  = theBestMeasurementFinder->findBestMeasurement(measurements, propagator);
882 
883  if (bestMeasurement) result.push_back(*bestMeasurement);
884  }
885  }
886  else {
887  measurements = theLayerMeasurements->measurements(layer, tsos, *propagator, *estimator);
888  const TrajectoryMeasurement* bestMeasurement
889  = theBestMeasurementFinder->findBestMeasurement(measurements, propagator);
890 
891  if (bestMeasurement) result.push_back(*bestMeasurement);
892  }
893  measurements.clear();
894 
895  return result;
896 
897 }
MuonDetLayerMeasurements * theLayerMeasurements
std::vector< TrajectoryMeasurementGroup > groupedMeasurements(const DetLayer *layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est, const edm::Event &iEvent)
MuonBestMeasurementFinder * theBestMeasurementFinder
tuple result
Definition: query.py:137
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 722 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by trajectories().

722  {
723 
725  if ( !lastTSOS.isValid() ) {
726  LogTrace(category_) << "Error: last TrajectoryState invalid.";
727  }
728  TransientTrackingRecHit::ConstRecHitContainer hits = traj.recHits();
729  std::reverse(hits.begin(), hits.end());
730 
731  LogTrace(category_) << "last tsos before flipping "<<lastTSOS;
732  utilities()->reverseDirection(lastTSOS,&*theService->magneticField());
733  LogTrace(category_) << "last tsos after flipping "<<lastTSOS;
734 
735  vector<Trajectory> refittedback = theSmoother->fit(traj.seed(),hits,lastTSOS);
736  if ( refittedback.empty() ) {
737  LogTrace(category_) <<"flipTrajectory fail. "<<endl;
738  return;
739  }
740  LogTrace(category_) <<"flipTrajectory: first "<< refittedback.front().firstMeasurement().updatedState()
741  <<"\nflipTrajectory: last "<<refittedback.front().lastMeasurement().updatedState();
742 
743  traj = refittedback.front();
744 
745  return;
746 
747 }
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:275
const CosmicMuonUtilities * utilities() const
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:181
#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 819 of file CosmicMuonTrajectoryBuilder.cc.

References category_, CSCDetId, cschits_, dthits_, DTLayerId, LogTrace, and PV3DBase< T, PVType, FrameType >::perp().

819  {
820 
821  TransientTrackingRecHit::ConstRecHitContainer hits = traj.recHits();
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();
831  << "pos" << pos
832  << "radius " << pos.perp()
833  << " dim " << (*ir)->dimension()
834  << " det " << (*ir)->det()->geographicalId().det()
835  << " sub det " << (*ir)->det()->subDetector()<<endl;
836 
837  if ((*ir)->det()->geographicalId().det() == 2 && (*ir)->det()->subDetector() == 6) {
838 // const CSCRecHit2D* iCSC = dynamic_cast<const CSCRecHit2D*>(&**ir);
839 // if (iCSC) LogTrace(category_)<<"csc from cast tpeak "<<iCSC->tpeak();
840  CSCRecHit2DCollection::range thisrange = cschits_->get(CSCDetId((*ir)->geographicalId()));
841  for (CSCRecHit2DCollection::const_iterator rechit = thisrange.first; rechit!=thisrange.second;++rechit) {
842  if ((*rechit).isValid()) LogTrace(category_)<<"csc from collection tpeak "<<(*rechit).tpeak();
843  }
844  }
845  if ((*ir)->det()->geographicalId().det() == 2 && (*ir)->det()->subDetector() == 7) {
846 // const DTRecHit1D* iDT = dynamic_cast<const DTRecHit1D*>(&**ir);
847 // if (iDT) LogTrace(category_)<<"dt digitime "<<iDT->digiTime();
848  DTRecHitCollection::range thisrange = dthits_->get(DTLayerId((*ir)->geographicalId()));
849  for (DTRecHitCollection::const_iterator rechit = thisrange.first; rechit!=thisrange.second;++rechit) {
850  if ((*rechit).isValid()) LogTrace(category_)<<"dt from collection digitime "<<(*rechit).digiTime();
851  }
852  }
853  }
854 
855  return;
856 
857 }
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
T perp() const
Definition: PV3DBase.h:72
edm::Handle< CSCRecHit2DCollection > cschits_
edm::Handle< DTRecHitCollection > dthits_
#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 903 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by build(), and trajectories().

907  {
908 
909  if (layer->subDetector()==GeomDetEnumerators::DT) dtChambers++;
910  else if (layer->subDetector()==GeomDetEnumerators::CSC) cscChambers++;
911  else if (layer->subDetector()==GeomDetEnumerators::RPCBarrel || layer->subDetector()==GeomDetEnumerators::RPCEndcap) rpcChambers++;
912  totalChambers++;
913 
914 }
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 596 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by buildSecondHalf().

596  {
597 
598  PerpendicularBoundPlaneBuilder planeBuilder;
599  GlobalPoint pos(0.0, 0.0, 0.0);
600  BoundPlane* SteppingPlane = planeBuilder(pos,tsos.globalDirection());
601 
602  TrajectoryStateOnSurface predTsos = propagator()->propagate(tsos, *SteppingPlane);
603  if ( predTsos.isValid() )
604  LogTrace(category_)<<"intermediateState: a intermediate state: pos: "<<predTsos.globalPosition() << "mom: " << predTsos.globalMomentum();
605 
606  return predTsos;
607 
608 }
const Propagator * propagator() const
virtual FreeTrajectoryState propagate(const FreeTrajectoryState &ftsStart, const GlobalPoint &pDest) const final
Definition: Propagator.h:119
#define LogTrace(id)
GlobalVector globalDirection() const
DirectMuonNavigation* CosmicMuonTrajectoryBuilder::navigation ( ) const
inline

Definition at line 73 of file CosmicMuonTrajectoryBuilder.h.

References theNavigation.

Referenced by build(), and trajectories().

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

Definition at line 58 of file CosmicMuonTrajectoryBuilder.h.

References MuonServiceProxy::propagator(), thePropagatorName, and theService.

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 61 of file CosmicMuonTrajectoryBuilder.h.

References MuonServiceProxy::propagator(), and theService.

Referenced by build().

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

Definition at line 63 of file CosmicMuonTrajectoryBuilder.h.

References MuonServiceProxy::propagator(), and theService.

Referenced by build().

63 {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 694 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by buildSecondHalf().

694  {
695 
696  PropagationDirection newDir = (traj.firstMeasurement().recHit()->globalPosition().y()
697  < traj.lastMeasurement().recHit()->globalPosition().y())
699  Trajectory newTraj(traj.seed(), newDir);
700 
701  /* does not work in gcc4.8?)
702  std::vector<TrajectoryMeasurement> & meas = traj.measurements();
703  for (auto itm = meas.rbegin(); itm != meas.rend(); ++itm ) {
704  newTraj.push(std::move(*itm));
705  }
706  traj = std::move(newTraj);
707  */
708 
709  std::vector<TrajectoryMeasurement> const & meas = traj.measurements();
710  for (auto itm = meas.rbegin(); itm != meas.rend(); ++itm ) {
711  newTraj.push(*itm);
712  }
713  traj = newTraj;
714 
715 
716 }
ConstRecHitPointer const & recHit() const
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:275
PropagationDirection
DataContainer const & measurements() const
Definition: Trajectory.h:203
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:181
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:194
void CosmicMuonTrajectoryBuilder::reverseTrajectoryPropagationDirection ( Trajectory traj) const
private

reverse the propagation direction of a trajectory

Definition at line 753 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by trajectories().

753  {
754 
755  if ( traj.direction() == anyDirection ) return;
757  Trajectory newTraj(traj.seed(), newDir);
758  const std::vector<TrajectoryMeasurement>& meas = traj.measurements();
759 
760  for (std::vector<TrajectoryMeasurement>::const_iterator itm = meas.begin(); itm != meas.end(); ++itm) {
761  newTraj.push(*itm);
762  }
763 
764  while (!traj.empty()) {
765  traj.pop();
766  }
767 
768  traj = newTraj;
769 
770 }
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:244
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:275
PropagationDirection
PropagationDirection const & direction() const
Definition: Trajectory.cc:118
DataContainer const & measurements() const
Definition: Trajectory.h:203
void pop()
Definition: Trajectory.cc:12
void CosmicMuonTrajectoryBuilder::selectHits ( MuonTransientTrackingRecHit::MuonRecHitContainer hits) const
private

Definition at line 614 of file CosmicMuonTrajectoryBuilder.cc.

References i, j, keep, and tmp.

614  {
615 
616  if ( hits.size() < 2 ) return;
617 
619  vector<bool> keep(hits.size(),true);
620  int i(0);
621  int j(0);
622 
623  for (MuonRecHitContainer::const_iterator ihit = hits.begin();
624  ihit != hits.end(); ++ihit ) {
625  if ( !keep[i] ) { i++; continue; };
626  j = i + 1;
627  for (MuonRecHitContainer::const_iterator ihit2 = ihit + 1;
628  ihit2 != hits.end(); ++ihit2 ) {
629  if ( !keep[j] ) { j++; continue; }
630  if ((*ihit)->geographicalId() == (*ihit2)->geographicalId() ) {
631  if ( (*ihit)->dimension() > (*ihit2)->dimension() ) {
632  keep[j] = false;
633  } else if ( (*ihit)->dimension() < (*ihit2)->dimension() ) {
634  keep[i] = false;
635  } else {
636  if ( (*ihit)->transientHits().size()>(*ihit2)->transientHits().size() ) {
637  keep[j] = false;
638  } else if ( (*ihit)->transientHits().size()<(*ihit2)->transientHits().size() ) {
639  keep[i] = false;
640  }
641  else if ( (*ihit)->degreesOfFreedom() != 0 && (*ihit2)->degreesOfFreedom() != 0) {
642  if (((*ihit)->chi2()/(*ihit)->degreesOfFreedom()) > ((*ihit2)->chi2()/(*ihit)->degreesOfFreedom())) keep[i] = false;
643  else keep[j] = false;
644  }
645  }
646  } // if same geomid
647  j++;
648  }
649  i++;
650  }
651 
652  i = 0;
653  for (MuonRecHitContainer::const_iterator ihit = hits.begin();
654  ihit != hits.end(); ++ihit ) {
655  if (keep[i] ) tmp.push_back(*ihit);
656  i++;
657  }
658 
659  hits.clear();
660  hits.swap(tmp);
661 
662  return;
663 
664 }
int i
Definition: DBlmapReader.cc:9
const int keep
int j
Definition: DBlmapReader.cc:9
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
bool CosmicMuonTrajectoryBuilder::selfDuplicate ( const Trajectory traj) const
private

check if the trajectory iterates the same hit more than once

Definition at line 670 of file CosmicMuonTrajectoryBuilder.cc.

References Trajectory::empty(), and query::result.

Referenced by trajectories().

670  {
671 
672  TransientTrackingRecHit::ConstRecHitContainer const & hits = traj.recHits();
673 
674  if (traj.empty()) return true;
675 
676  bool result = false;
677  for (ConstRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++ ) {
678  if ( !(*ir)->isValid() ) continue;
679  for (ConstRecHitContainer::const_iterator ir2 = ir+1; ir2 != hits.end(); ir2++ ) {
680  if ( !(*ir2)->isValid() ) continue;
681  if ( (*ir) == (*ir2) ) result = true;
682  }
683  }
684 
685  return result;
686 
687 }
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:244
tuple result
Definition: query.py:137
std::vector< ConstRecHitPointer > ConstRecHitContainer
void CosmicMuonTrajectoryBuilder::setEvent ( const edm::Event event)
virtual

pass the Event to the algo at each event

Implements MuonTrajectoryBuilder.

Definition at line 117 of file CosmicMuonTrajectoryBuilder.cc.

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

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

Definition at line 69 of file CosmicMuonTrajectoryBuilder.h.

References theSmoother.

Referenced by utilities().

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

Definition at line 920 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by checkDirectionByT0().

920  {
921 
922  if ( (dtseg == 0) || (!dtseg->hasPhi()) ) return 0;
923  // timing information
924  double result = 0;
925  if ( dtseg->phiSegment() == 0 ) return 0;
926  int phiHits = dtseg->phiSegment()->specificRecHits().size();
927  LogTrace(category_) << "phiHits " << phiHits;
928  if ( phiHits > 5 ) {
929  if(dtseg->phiSegment()->ist0Valid()) result = dtseg->phiSegment()->t0();
930  if (dtseg->phiSegment()->ist0Valid()){
931  LogTrace(category_) << " Phi t0: " << dtseg->phiSegment()->t0() << " hits: " << phiHits;
932  } else {
933  LogTrace(category_) << " Phi t0 is invalid: " << dtseg->phiSegment()->t0() << " hits: " << phiHits;
934  }
935  }
936 
937  return result;
938 
939 }
tuple result
Definition: query.py:137
#define LogTrace(id)
MuonTrajectoryBuilder::TrajectoryContainer CosmicMuonTrajectoryBuilder::trajectories ( const TrajectorySeed seed)
virtual

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

dummy implementation, unused in this class

Implements MuonTrajectoryBuilder.

Definition at line 52 of file CosmicMuonTrajectoryBuilder.h.

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

Definition at line 454 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by trajectories().

454  {
455 
458  for (MuonRecHitContainer::const_iterator ihit = tmpHits.begin();
459  ihit != tmpHits.end(); ++ihit ) {
460  if ((*ihit)->geographicalId() != meas.recHit()->geographicalId() ){
461  result.push_back(*ihit);
462  LogTrace(category_) << "Unused hit: " << (*ihit)->globalPosition() << endl;
463  }
464  }
465 
466  return result;
467 
468 }
ConstRecHitPointer const & recHit() const
MuonDetLayerMeasurements * theLayerMeasurements
MuonRecHitContainer recHits(const DetLayer *layer, const edm::Event &iEvent)
returns the rechits which are on the layer
tuple result
Definition: query.py:137
#define LogTrace(id)
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
std::vector< MuonRecHitPointer > MuonRecHitContainer
MuonTrajectoryUpdator* CosmicMuonTrajectoryBuilder::updator ( ) const
inline

Definition at line 65 of file CosmicMuonTrajectoryBuilder.h.

References theUpdator.

Referenced by build(), and trajectories().

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

Definition at line 71 of file CosmicMuonTrajectoryBuilder.h.

References smoother(), and CosmicMuonSmoother::utilities().

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

71 {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 138 of file CosmicMuonTrajectoryBuilder.h.

Referenced by getDirectionByTime().

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

Definition at line 139 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 137 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 117 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 128 of file CosmicMuonTrajectoryBuilder.h.

Referenced by CosmicMuonTrajectoryBuilder(), and propagator().

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

Definition at line 131 of file CosmicMuonTrajectoryBuilder.h.

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

bool CosmicMuonTrajectoryBuilder::theTraversingMuonFlag
private

Definition at line 130 of file CosmicMuonTrajectoryBuilder.h.

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

MuonTrajectoryUpdator* CosmicMuonTrajectoryBuilder::theUpdator
private