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 // if(enableDTMeasurement)
53  InputTag DTRecSegmentLabel = par.getParameter<InputTag>("DTRecSegmentLabel");
54 
55 // if(enableCSCMeasurement)
56  InputTag CSCRecSegmentLabel = par.getParameter<InputTag>("CSCRecSegmentLabel");
57 
58 // if(enableRPCMeasurement)
59  InputTag RPCRecSegmentLabel = par.getParameter<InputTag>("RPCRecSegmentLabel");
60  theLayerMeasurements= new MuonDetLayerMeasurements(DTRecSegmentLabel,
61  CSCRecSegmentLabel,
62  RPCRecSegmentLabel,
63  iC,
64  enableDTMeasurement,
65  enableCSCMeasurement,
66  enableRPCMeasurement);
67 
68  ParameterSet muonUpdatorPSet = par.getParameter<ParameterSet>("MuonTrajectoryUpdatorParameters");
69 
70  theNavigation = 0; // new DirectMuonNavigation(theService->detLayerGeometry());
71  theUpdator = new MuonTrajectoryUpdator(muonUpdatorPSet, insideOut);
72 
74 
75  ParameterSet muonBackwardUpdatorPSet = par.getParameter<ParameterSet>("BackwardMuonTrajectoryUpdatorParameters");
76 
77  theBKUpdator = new MuonTrajectoryUpdator(muonBackwardUpdatorPSet, outsideIn);
78 
79  theTraversingMuonFlag = par.getParameter<bool>("BuildTraversingMuon");
80 
81  theStrict1LegFlag = par.getParameter<bool>("Strict1Leg");
82 
83  ParameterSet smootherPSet = par.getParameter<ParameterSet>("MuonSmootherParameters");
84 
85  theNavigationPSet = par.getParameter<ParameterSet>("MuonNavigationParameters");
86 
87  theSmoother = new CosmicMuonSmoother(smootherPSet,theService);
88 
89  theNTraversing = 0;
90  theNSuccess = 0;
91  theCacheId_DG = 0;
92  category_ = "Muon|RecoMuon|CosmicMuon|CosmicMuonTrajectoryBuilder";
93 
94 }
T getParameter(std::string const &) const
MuonDetLayerMeasurements * theLayerMeasurements
MuonBestMeasurementFinder * theBestMeasurementFinder
CosmicMuonTrajectoryBuilder::~CosmicMuonTrajectoryBuilder ( )
virtual

Destructor.

Definition at line 97 of file CosmicMuonTrajectoryBuilder.cc.

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

97  {
98 
99  LogTrace(category_)<< "CosmicMuonTrajectoryBuilder dtor called";
100  if (theUpdator) delete theUpdator;
101  if (theBKUpdator) delete theBKUpdator;
103  if (theSmoother) delete theSmoother;
104  if (theNavigation) delete theNavigation;
106 
107  LogTrace(category_)<< "CosmicMuonTrajectoryBuilder Traversing: "<<theNSuccess<<"/"<<theNTraversing;
108 
109 }
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 469 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(), 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().

471  {
472 
473  if ( !ts.isValid() ) return;
474 
475  const FreeTrajectoryState* fts = ts.freeState();
476  if ( !fts ) return;
477 
478  vector<const DetLayer*> navLayers;
479 
480  if (fabs(fts->momentum().basicVector().eta()) < 1.0) {
481  //DT
482  if (fts->position().basicVector().dot(fts->momentum().basicVector())>0){
483  navLayers = navigation()->compatibleLayers((*fts), alongMomentum);
484  } else {
485  navLayers = navigation()->compatibleLayers((*fts), oppositeToMomentum);
486  }
487 
489  //CSC
490  if (fts->position().basicVector().dot(fts->momentum().basicVector())>0){
491  navLayers = navigation()->compatibleEndcapLayers((*fts), alongMomentum);
492  } else {
493  navLayers = navigation()->compatibleEndcapLayers((*fts), oppositeToMomentum);
494  }
495  } else {
496 
497  if (fts->position().basicVector().dot(fts->momentum().basicVector())>0){
498  navLayers = navigation()->compatibleLayers((*fts), alongMomentum);
499  } else {
500  navLayers = navigation()->compatibleLayers((*fts), oppositeToMomentum);
501  }
502 
503 }
504 
505  if (navLayers.empty()) return;
506 
507  theBKUpdator->setFitDirection(startingDir);
508 
509  int DTChamberUsedBack = 0;
510  int CSCChamberUsedBack = 0;
511  int RPCChamberUsedBack = 0;
512  int TotalChamberUsedBack = 0;
513 
514  TrajectoryStateOnSurface lastTsos =
517  propagatorAlong()->propagate((*fts),navLayers.front()->surface()) : propagatorOpposite()->propagate((*fts),navLayers.front()->surface());
518 
519  if ( !lastTsos.isValid() ) {
520  LogTrace(category_)<<"propagation failed from fts to inner cylinder";
521  return;
522  }
523  LogTrace(category_)<<"tsos "<<lastTsos.globalPosition();
524  lastTsos.rescaleError(10.);
525  vector<TrajectoryMeasurement> measL;
526  for (vector<const DetLayer*>::const_iterator rnxtlayer = navLayers.begin();
527  rnxtlayer!= navLayers.end(); ++rnxtlayer) {
528 
529  measL.clear();
530  measL = findBestMeasurements(*rnxtlayer, lastTsos, propagator(), (backwardUpdator()->estimator()));
531 
532  if ( measL.empty() ) continue;
533 
534  for (vector<TrajectoryMeasurement>::const_iterator theMeas = measL.begin(); theMeas != measL.end(); ++theMeas) {
535 
536  pair<bool,TrajectoryStateOnSurface> bkresult
537  = backwardUpdator()->update((&*theMeas), traj, propagator());
538  if (bkresult.first ) {
539  LogTrace(category_)<<"update ok : "<<(theMeas)->recHit()->globalPosition() ;
540 
541  incrementChamberCounters((*rnxtlayer), DTChamberUsedBack, CSCChamberUsedBack, RPCChamberUsedBack, TotalChamberUsedBack);
542 
543  if ( (!traj.empty()) && bkresult.second.isValid() )
544  lastTsos = bkresult.second;
545  else if ((theMeas)->predictedState().isValid())
546  lastTsos = (theMeas)->predictedState();
547  }
548  }
549  }
550  navLayers.clear();
551  updator()->makeFirstTime();
553 
554  measL.clear();
555 
556  return;
557 
558 }
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
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
if(conf.exists("allCellsPositionCalc"))
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 565 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().

565  {
566 
567  if ( (traj.firstMeasurement().recHit()->globalPosition().perp()
568  < traj.lastMeasurement().recHit()->globalPosition().perp()) ) {
569  LogTrace(category_)<<"inside-out: reverseTrajectory";
570  reverseTrajectory(traj);
571  }
572  if (traj.empty()) return;
574  if ( !tsos.isValid() ) tsos = traj.lastMeasurement().predictedState();
575  LogTrace(category_)<<"last tsos on traj: pos: "<< tsos.globalPosition()<<" mom: "<< tsos.globalMomentum();
576  if ( !tsos.isValid() ) {
577  LogTrace(category_)<<"last tsos on traj invalid";
578  return;
579  }
580 
581  build(intermediateState(tsos),insideOut,traj);
582 
583  return;
584 
585 }
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 940 of file CosmicMuonTrajectoryBuilder.cc.

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

941  {
942 
943  LogTrace(category_) << "comparing dtseg: " << dtseg1 << " " << dtseg2 << endl;
944  if (dtseg1 == dtseg2 || t0(dtseg1) == t0(dtseg2)) return anyDirection;
945 
947  ( t0(dtseg1) < t0(dtseg2) ) ? alongMomentum : oppositeToMomentum;
948 
949  return result;
950 
951 }
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 771 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().

771  {
772 
773  TransientTrackingRecHit::ConstRecHitContainer hits = traj.recHits();
774 
776 
778 
779  if ( !firstTSOS.isValid() || !lastTSOS.isValid() ) return;
780 
781  LogTrace(category_) <<"Two ends of the traj "<<firstTSOS.globalPosition()
782  <<", "<<lastTSOS.globalPosition();
783 
784  LogTrace(category_) <<"Their mom: "<<firstTSOS.globalMomentum()
785  <<", "<<lastTSOS.globalMomentum();
786 
787  LogTrace(category_) <<"Their mom eta: "<<firstTSOS.globalMomentum().eta()
788  <<", "<<lastTSOS.globalMomentum().eta();
789 
790  // momentum eta can be used to estimate direction
791  // the beam-halo muon seems enter with a larger |eta|
792 
793  if ( fabs(firstTSOS.globalMomentum().eta()) > fabs(lastTSOS.globalMomentum().eta()) ) {
794 
795  vector<Trajectory> refitted = theSmoother->trajectories(traj.seed(),hits,firstTSOS);
796  if ( !refitted.empty() ) traj = refitted.front();
797 
798  } else {
799  std::reverse(hits.begin(), hits.end());
800  utilities()->reverseDirection(lastTSOS,&*theService->magneticField());
801  vector<Trajectory> refittedback = theSmoother->trajectories(traj.seed(),hits,lastTSOS);
802  if ( !refittedback.empty() ) traj = refittedback.front();
803 
804  }
805 
806  return;
807 
808 }
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 859 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by build(), and trajectories().

862  {
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(); ++tmGroupItr) {
873 
874  measurements = tmGroupItr->measurements();
875  const TrajectoryMeasurement* bestMeasurement
876  = theBestMeasurementFinder->findBestMeasurement(measurements, propagator);
877 
878  if (bestMeasurement) result.push_back(*bestMeasurement);
879  }
880  }
881  else {
882  measurements = theLayerMeasurements->measurements(layer, tsos, *propagator, *estimator);
883  const TrajectoryMeasurement* bestMeasurement
884  = theBestMeasurementFinder->findBestMeasurement(measurements, propagator);
885 
886  if (bestMeasurement) result.push_back(*bestMeasurement);
887  }
888  measurements.clear();
889 
890  return result;
891 
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
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 717 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().

717  {
718 
720  if ( !lastTSOS.isValid() ) {
721  LogTrace(category_) << "Error: last TrajectoryState invalid.";
722  }
723  TransientTrackingRecHit::ConstRecHitContainer hits = traj.recHits();
724  std::reverse(hits.begin(), hits.end());
725 
726  LogTrace(category_) << "last tsos before flipping "<<lastTSOS;
727  utilities()->reverseDirection(lastTSOS,&*theService->magneticField());
728  LogTrace(category_) << "last tsos after flipping "<<lastTSOS;
729 
730  vector<Trajectory> refittedback = theSmoother->fit(traj.seed(),hits,lastTSOS);
731  if ( refittedback.empty() ) {
732  LogTrace(category_) <<"flipTrajectory fail. "<<endl;
733  return;
734  }
735  LogTrace(category_) <<"flipTrajectory: first "<< refittedback.front().firstMeasurement().updatedState()
736  <<"\nflipTrajectory: last "<<refittedback.front().lastMeasurement().updatedState();
737 
738  traj = refittedback.front();
739 
740  return;
741 
742 }
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 814 of file CosmicMuonTrajectoryBuilder.cc.

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

814  {
815 
816  TransientTrackingRecHit::ConstRecHitContainer hits = traj.recHits();
817  LogTrace(category_) << "getDirectionByTime"<<endl;
818  for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++ ) {
819  if ( !(*ir)->isValid() ) {
820  LogTrace(category_) << "invalid RecHit"<<endl;
821  continue;
822  }
823 
824  const GlobalPoint& pos = (*ir)->globalPosition();
826  << "pos" << pos
827  << "radius " << pos.perp()
828  << " dim " << (*ir)->dimension()
829  << " det " << (*ir)->det()->geographicalId().det()
830  << " sub det " << (*ir)->det()->subDetector()<<endl;
831 
832  if ((*ir)->det()->geographicalId().det() == 2 && (*ir)->det()->subDetector() == 6) {
833 // const CSCRecHit2D* iCSC = dynamic_cast<const CSCRecHit2D*>(&**ir);
834 // if (iCSC) LogTrace(category_)<<"csc from cast tpeak "<<iCSC->tpeak();
835  CSCRecHit2DCollection::range thisrange = cschits_->get(CSCDetId((*ir)->geographicalId()));
836  for (CSCRecHit2DCollection::const_iterator rechit = thisrange.first; rechit!=thisrange.second;++rechit) {
837  if ((*rechit).isValid()) LogTrace(category_)<<"csc from collection tpeak "<<(*rechit).tpeak();
838  }
839  }
840  if ((*ir)->det()->geographicalId().det() == 2 && (*ir)->det()->subDetector() == 7) {
841 // const DTRecHit1D* iDT = dynamic_cast<const DTRecHit1D*>(&**ir);
842 // if (iDT) LogTrace(category_)<<"dt digitime "<<iDT->digiTime();
843  DTRecHitCollection::range thisrange = dthits_->get(DTLayerId((*ir)->geographicalId()));
844  for (DTRecHitCollection::const_iterator rechit = thisrange.first; rechit!=thisrange.second;++rechit) {
845  if ((*rechit).isValid()) LogTrace(category_)<<"dt from collection digitime "<<(*rechit).digiTime();
846  }
847  }
848  }
849 
850  return;
851 
852 }
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 898 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by build(), and trajectories().

902  {
903 
904  if (layer->subDetector()==GeomDetEnumerators::DT) dtChambers++;
905  else if (layer->subDetector()==GeomDetEnumerators::CSC) cscChambers++;
906  else if (layer->subDetector()==GeomDetEnumerators::RPCBarrel || layer->subDetector()==GeomDetEnumerators::RPCEndcap) rpcChambers++;
907  totalChambers++;
908 
909 }
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 591 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by buildSecondHalf().

591  {
592 
593  PerpendicularBoundPlaneBuilder planeBuilder;
594  GlobalPoint pos(0.0, 0.0, 0.0);
595  BoundPlane* SteppingPlane = planeBuilder(pos,tsos.globalDirection());
596 
597  TrajectoryStateOnSurface predTsos = propagator()->propagate(tsos, *SteppingPlane);
598  if ( predTsos.isValid() )
599  LogTrace(category_)<<"intermediateState: a intermediate state: pos: "<<predTsos.globalPosition() << "mom: " << predTsos.globalMomentum();
600 
601  return predTsos;
602 
603 }
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 689 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by buildSecondHalf().

689  {
690 
691  PropagationDirection newDir = (traj.firstMeasurement().recHit()->globalPosition().y()
692  < traj.lastMeasurement().recHit()->globalPosition().y())
694  Trajectory newTraj(traj.seed(), newDir);
695 
696  /* does not work in gcc4.8?)
697  std::vector<TrajectoryMeasurement> & meas = traj.measurements();
698  for (auto itm = meas.rbegin(); itm != meas.rend(); ++itm ) {
699  newTraj.push(std::move(*itm));
700  }
701  traj = std::move(newTraj);
702  */
703 
704  std::vector<TrajectoryMeasurement> const & meas = traj.measurements();
705  for (auto itm = meas.rbegin(); itm != meas.rend(); ++itm ) {
706  newTraj.push(*itm);
707  }
708  traj = newTraj;
709 
710 
711 }
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 748 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by trajectories().

748  {
749 
750  if ( traj.direction() == anyDirection ) return;
752  Trajectory newTraj(traj.seed(), newDir);
753  const std::vector<TrajectoryMeasurement>& meas = traj.measurements();
754 
755  for (std::vector<TrajectoryMeasurement>::const_iterator itm = meas.begin(); itm != meas.end(); ++itm) {
756  newTraj.push(*itm);
757  }
758 
759  while (!traj.empty()) {
760  traj.pop();
761  }
762 
763  traj = newTraj;
764 
765 }
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 609 of file CosmicMuonTrajectoryBuilder.cc.

References i, j, keep, and tmp.

609  {
610 
611  if ( hits.size() < 2 ) return;
612 
614  vector<bool> keep(hits.size(),true);
615  int i(0);
616  int j(0);
617 
618  for (MuonRecHitContainer::const_iterator ihit = hits.begin();
619  ihit != hits.end(); ++ihit ) {
620  if ( !keep[i] ) { i++; continue; };
621  j = i + 1;
622  for (MuonRecHitContainer::const_iterator ihit2 = ihit + 1;
623  ihit2 != hits.end(); ++ihit2 ) {
624  if ( !keep[j] ) { j++; continue; }
625  if ((*ihit)->geographicalId() == (*ihit2)->geographicalId() ) {
626  if ( (*ihit)->dimension() > (*ihit2)->dimension() ) {
627  keep[j] = false;
628  } else if ( (*ihit)->dimension() < (*ihit2)->dimension() ) {
629  keep[i] = false;
630  } else {
631  if ( (*ihit)->transientHits().size()>(*ihit2)->transientHits().size() ) {
632  keep[j] = false;
633  } else if ( (*ihit)->transientHits().size()<(*ihit2)->transientHits().size() ) {
634  keep[i] = false;
635  }
636  else if ( (*ihit)->degreesOfFreedom() != 0 && (*ihit2)->degreesOfFreedom() != 0) {
637  if (((*ihit)->chi2()/(*ihit)->degreesOfFreedom()) > ((*ihit2)->chi2()/(*ihit)->degreesOfFreedom())) keep[i] = false;
638  else keep[j] = false;
639  }
640  }
641  } // if same geomid
642  j++;
643  }
644  i++;
645  }
646 
647  i = 0;
648  for (MuonRecHitContainer::const_iterator ihit = hits.begin();
649  ihit != hits.end(); ++ihit ) {
650  if (keep[i] ) tmp.push_back(*ihit);
651  i++;
652  }
653 
654  hits.clear();
655  hits.swap(tmp);
656 
657  return;
658 
659 }
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 665 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by trajectories().

665  {
666 
667  TransientTrackingRecHit::ConstRecHitContainer const & hits = traj.recHits();
668 
669  if (traj.empty()) return true;
670 
671  bool result = false;
672  for (ConstRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++ ) {
673  if ( !(*ir)->isValid() ) continue;
674  for (ConstRecHitContainer::const_iterator ir2 = ir+1; ir2 != hits.end(); ir2++ ) {
675  if ( !(*ir2)->isValid() ) continue;
676  if ( (*ir) == (*ir2) ) result = true;
677  }
678  }
679 
680  return result;
681 
682 }
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 112 of file CosmicMuonTrajectoryBuilder.cc.

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

112  {
113 
115 
116  // DetLayer Geometry
117  unsigned long long newCacheId_DG = theService->eventSetup().get<MuonRecoGeometryRecord>().cacheIdentifier();
118  if ( newCacheId_DG != theCacheId_DG ) {
119  LogTrace(category_) << "Muon Reco Geometry changed!";
120  theCacheId_DG = newCacheId_DG;
121  if (theNavigation) delete theNavigation;
123  }
124 
125 
126 }
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 915 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by checkDirectionByT0().

915  {
916 
917  if ( (dtseg == 0) || (!dtseg->hasPhi()) ) return 0;
918  // timing information
919  double result = 0;
920  if ( dtseg->phiSegment() == 0 ) return 0;
921  int phiHits = dtseg->phiSegment()->specificRecHits().size();
922  LogTrace(category_) << "phiHits " << phiHits;
923  if ( phiHits > 5 ) {
924  if(dtseg->phiSegment()->ist0Valid()) result = dtseg->phiSegment()->t0();
925  if (dtseg->phiSegment()->ist0Valid()){
926  LogTrace(category_) << " Phi t0: " << dtseg->phiSegment()->t0() << " hits: " << phiHits;
927  } else {
928  LogTrace(category_) << " Phi t0 is invalid: " << dtseg->phiSegment()->t0() << " hits: " << phiHits;
929  }
930  }
931 
932  return result;
933 
934 }
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 130 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(), 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(), tree::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().

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

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

Referenced by trajectories().

449  {
450 
453  for (MuonRecHitContainer::const_iterator ihit = tmpHits.begin();
454  ihit != tmpHits.end(); ++ihit ) {
455  if ((*ihit)->geographicalId() != meas.recHit()->geographicalId() ){
456  result.push_back(*ihit);
457  LogTrace(category_) << "Unused hit: " << (*ihit)->globalPosition() << endl;
458  }
459  }
460 
461  return result;
462 
463 }
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