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

Constructor & Destructor Documentation

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

Constructor.

Definition at line 46 of file CosmicMuonTrajectoryBuilder.cc.

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

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

Destructor.

Definition at line 99 of file CosmicMuonTrajectoryBuilder.cc.

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

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

Member Function Documentation

MuonTrajectoryUpdator* CosmicMuonTrajectoryBuilder::backwardUpdator ( ) const
inline

Definition at line 68 of file CosmicMuonTrajectoryBuilder.h.

References theBKUpdator.

Referenced by build(), and trajectories().

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

Definition at line 76 of file CosmicMuonTrajectoryBuilder.h.

References theBestMeasurementFinder.

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

Definition at line 473 of file CosmicMuonTrajectoryBuilder.cc.

References alongMomentum, backwardUpdator(), PV3DBase< T, PVType, FrameType >::basicVector(), category_, DirectMuonNavigation::compatibleEndcapLayers(), DirectMuonNavigation::compatibleLayers(), Basic3DVector< T >::dot(), Trajectory::empty(), Basic3DVector< T >::eta(), findBestMeasurements(), Trajectory::firstMeasurement(), TrajectoryStateOnSurface::freeState(), TrajectoryStateOnSurface::globalPosition(), 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().

475  {
476 
477  if ( !ts.isValid() ) return;
478 
479  FreeTrajectoryState* fts = ts.freeState();
480  if ( !fts ) return;
481 
482  vector<const DetLayer*> navLayers;
483 
484  if (fabs(fts->momentum().basicVector().eta()) < 1.0) {
485  //DT
486  if (fts->position().basicVector().dot(fts->momentum().basicVector())>0){
487  navLayers = navigation()->compatibleLayers((*fts), alongMomentum);
488  } else {
489  navLayers = navigation()->compatibleLayers((*fts), oppositeToMomentum);
490  }
491 
493  //CSC
494  if (fts->position().basicVector().dot(fts->momentum().basicVector())>0){
495  navLayers = navigation()->compatibleEndcapLayers((*fts), alongMomentum);
496  } else {
497  navLayers = navigation()->compatibleEndcapLayers((*fts), oppositeToMomentum);
498  }
499  } else {
500 
501  if (fts->position().basicVector().dot(fts->momentum().basicVector())>0){
502  navLayers = navigation()->compatibleLayers((*fts), alongMomentum);
503  } else {
504  navLayers = navigation()->compatibleLayers((*fts), oppositeToMomentum);
505  }
506 
507 }
508 
509  if (navLayers.empty()) return;
510 
511  theBKUpdator->setFitDirection(startingDir);
512 
513  int DTChamberUsedBack = 0;
514  int CSCChamberUsedBack = 0;
515  int RPCChamberUsedBack = 0;
516  int TotalChamberUsedBack = 0;
517 
518  TrajectoryStateOnSurface lastTsos =
521  propagatorAlong()->propagate((*fts),navLayers.front()->surface()) : propagatorOpposite()->propagate((*fts),navLayers.front()->surface());
522 
523  if ( !lastTsos.isValid() ) {
524  LogTrace(category_)<<"propagation failed from fts to inner cylinder";
525  return;
526  }
527  LogTrace(category_)<<"tsos "<<lastTsos.globalPosition();
528  lastTsos.rescaleError(10.);
529  vector<TrajectoryMeasurement> measL;
530  for (vector<const DetLayer*>::const_iterator rnxtlayer = navLayers.begin();
531  rnxtlayer!= navLayers.end(); ++rnxtlayer) {
532 
533  measL.clear();
534  measL = findBestMeasurements(*rnxtlayer, lastTsos, propagator(), (backwardUpdator()->estimator()));
535 
536  if ( measL.empty() ) continue;
537 
538  for (vector<TrajectoryMeasurement>::const_iterator theMeas = measL.begin(); theMeas != measL.end(); ++theMeas) {
539 
540  pair<bool,TrajectoryStateOnSurface> bkresult
541  = backwardUpdator()->update((&*theMeas), traj, propagator());
542  if (bkresult.first ) {
543  LogTrace(category_)<<"update ok : "<<(theMeas)->recHit()->globalPosition() ;
544 
545  incrementChamberCounters((*rnxtlayer), DTChamberUsedBack, CSCChamberUsedBack, RPCChamberUsedBack, TotalChamberUsedBack);
546 
547  if ( (!traj.empty()) && bkresult.second.isValid() )
548  lastTsos = bkresult.second;
549  else if ((theMeas)->predictedState().isValid())
550  lastTsos = (theMeas)->predictedState();
551  }
552  }
553  }
554  navLayers.clear();
555  updator()->makeFirstTime();
557 
558  measL.clear();
559 
560  return;
561 
562 }
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:234
const Propagator * propagator() const
std::vector< const DetLayer * > compatibleEndcapLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection) const
void makeFirstTime()
reset the theFirstTSOSFlag
T y() const
Definition: PV3DBase.h:62
MuonTrajectoryUpdator * backwardUpdator() const
GlobalPoint globalPosition() const
const Propagator * propagatorOpposite() const
std::vector< const DetLayer * > compatibleLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection) const
DirectMuonNavigation * navigation() const
FreeTrajectoryState * freeState(bool withErrors=true) const
MuonTrajectoryUpdator * updator() const
void setFitDirection(NavigationDirection fitDirection)
set fit direction
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:181
TrajectoryStateOnSurface updatedState() const
void incrementChamberCounters(const DetLayer *layer, int &dtChambers, int &cscChambers, int &rpcChambers, int &totalChambers)
#define LogTrace(id)
GlobalVector momentum() const
virtual TrajectoryStateOnSurface propagate(const FreeTrajectoryState &, const Surface &) const
Definition: Propagator.cc:12
GlobalPoint position() const
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:194
const Propagator * propagatorAlong() const
perl if(1 lt scalar(@::datatypes))
Definition: edlooper.cc:31
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
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 569 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().

569  {
570 
571  if ( (traj.firstMeasurement().recHit()->globalPosition().perp()
572  < traj.lastMeasurement().recHit()->globalPosition().perp()) ) {
573  LogTrace(category_)<<"inside-out: reverseTrajectory";
574  reverseTrajectory(traj);
575  }
576  if (traj.empty()) return;
578  if ( !tsos.isValid() ) tsos = traj.lastMeasurement().predictedState();
579  LogTrace(category_)<<"last tsos on traj: pos: "<< tsos.globalPosition()<<" mom: "<< tsos.globalMomentum();
580  if ( !tsos.isValid() ) {
581  LogTrace(category_)<<"last tsos on traj invalid";
582  return;
583  }
584 
585  build(intermediateState(tsos),insideOut,traj);
586 
587  return;
588 
589 }
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:234
TrajectoryStateOnSurface intermediateState(const TrajectoryStateOnSurface &) const
GlobalPoint globalPosition() const
ConstRecHitPointer recHit() const
void reverseTrajectory(Trajectory &) const
reverse a trajectory without refit (out the measurements order changed)
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:181
TrajectoryStateOnSurface updatedState() const
TrajectoryStateOnSurface predictedState() const
#define LogTrace(id)
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:194
GlobalVector globalMomentum() const
void build(const TrajectoryStateOnSurface &, const NavigationDirection &, Trajectory &)
PropagationDirection CosmicMuonTrajectoryBuilder::checkDirectionByT0 ( const DTRecSegment4D dtseg1,
const DTRecSegment4D dtseg2 
) const

Definition at line 937 of file CosmicMuonTrajectoryBuilder.cc.

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

938  {
939 
940  LogTrace(category_) << "comparing dtseg: " << dtseg1 << " " << dtseg2 << endl;
941  if (dtseg1 == dtseg2 || t0(dtseg1) == t0(dtseg2)) return anyDirection;
942 
944  ( t0(dtseg1) < t0(dtseg2) ) ? alongMomentum : oppositeToMomentum;
945 
946  return result;
947 
948 }
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 768 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by trajectories().

768  {
769 
771 
773 
775 
776  if ( !firstTSOS.isValid() || !lastTSOS.isValid() ) return;
777 
778  LogTrace(category_) <<"Two ends of the traj "<<firstTSOS.globalPosition()
779  <<", "<<lastTSOS.globalPosition();
780 
781  LogTrace(category_) <<"Their mom: "<<firstTSOS.globalMomentum()
782  <<", "<<lastTSOS.globalMomentum();
783 
784  LogTrace(category_) <<"Their mom eta: "<<firstTSOS.globalMomentum().eta()
785  <<", "<<lastTSOS.globalMomentum().eta();
786 
787  // momentum eta can be used to estimate direction
788  // the beam-halo muon seems enter with a larger |eta|
789 
790  if ( fabs(firstTSOS.globalMomentum().eta()) > fabs(lastTSOS.globalMomentum().eta()) ) {
791 
792  vector<Trajectory> refitted = theSmoother->trajectories(traj.seed(),hits,firstTSOS);
793  if ( !refitted.empty() ) traj = refitted.front();
794 
795  } else {
796  std::reverse(hits.begin(), hits.end());
797  utilities()->reverseDirection(lastTSOS,&*theService->magneticField());
798  vector<Trajectory> refittedback = theSmoother->trajectories(traj.seed(),hits,lastTSOS);
799  if ( !refittedback.empty() ) traj = refittedback.front();
800 
801  }
802 
803  return;
804 
805 }
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:265
GlobalPoint globalPosition() const
ConstRecHitContainer recHits(bool splitting=false) const
Definition: Trajectory.cc:67
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:181
TrajectoryStateOnSurface updatedState() const
#define LogTrace(id)
std::vector< ConstRecHitPointer > ConstRecHitContainer
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:194
CosmicMuonUtilities * utilities() const
T eta() const
Definition: PV3DBase.h:75
GlobalVector globalMomentum() const
virtual std::vector< Trajectory > trajectories(const Trajectory &) 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 856 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by build(), and trajectories().

859  {
860 
861  std::vector<TrajectoryMeasurement> result;
862  std::vector<TrajectoryMeasurement> measurements;
863 
864  if ( layer->hasGroups() ) {
865  std::vector<TrajectoryMeasurementGroup> measurementGroups =
866  theLayerMeasurements->groupedMeasurements(layer, tsos, *propagator, *estimator);
867 
868  for (std::vector<TrajectoryMeasurementGroup>::const_iterator tmGroupItr = measurementGroups.begin();
869  tmGroupItr != measurementGroups.end(); ++tmGroupItr) {
870 
871  measurements = tmGroupItr->measurements();
872  const TrajectoryMeasurement* bestMeasurement
873  = theBestMeasurementFinder->findBestMeasurement(measurements, propagator);
874 
875  if (bestMeasurement) result.push_back(*bestMeasurement);
876  }
877  }
878  else {
879  measurements = theLayerMeasurements->measurements(layer, tsos, *propagator, *estimator);
880  const TrajectoryMeasurement* bestMeasurement
881  = theBestMeasurementFinder->findBestMeasurement(measurements, propagator);
882 
883  if (bestMeasurement) result.push_back(*bestMeasurement);
884  }
885  measurements.clear();
886 
887  return result;
888 
889 }
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)
virtual bool hasGroups() const =0
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 714 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by trajectories().

714  {
715 
717  if ( !lastTSOS.isValid() ) {
718  LogTrace(category_) << "Error: last TrajectoryState invalid.";
719  }
721  std::reverse(hits.begin(), hits.end());
722 
723  LogTrace(category_) << "last tsos before flipping "<<lastTSOS;
724  utilities()->reverseDirection(lastTSOS,&*theService->magneticField());
725  LogTrace(category_) << "last tsos after flipping "<<lastTSOS;
726 
727  vector<Trajectory> refittedback = theSmoother->fit(traj.seed(),hits,lastTSOS);
728  if ( refittedback.empty() ) {
729  LogTrace(category_) <<"flipTrajectory fail. "<<endl;
730  return;
731  }
732  LogTrace(category_) <<"flipTrajectory: first "<< refittedback.front().firstMeasurement().updatedState()
733  <<"\nflipTrajectory: last "<<refittedback.front().lastMeasurement().updatedState();
734 
735  traj = refittedback.front();
736 
737  return;
738 
739 }
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:265
ConstRecHitContainer recHits(bool splitting=false) const
Definition: Trajectory.cc:67
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:181
TrajectoryStateOnSurface updatedState() const
#define LogTrace(id)
std::vector< ConstRecHitPointer > ConstRecHitContainer
std::vector< Trajectory > fit(const Trajectory &) const
CosmicMuonUtilities * utilities() 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 811 of file CosmicMuonTrajectoryBuilder.cc.

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

811  {
812 
814  LogTrace(category_) << "getDirectionByTime"<<endl;
815  for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++ ) {
816  if ( !(*ir)->isValid() ) {
817  LogTrace(category_) << "invalid RecHit"<<endl;
818  continue;
819  }
820 
821  const GlobalPoint& pos = (*ir)->globalPosition();
823  << "pos" << pos
824  << "radius " << pos.perp()
825  << " dim " << (*ir)->dimension()
826  << " det " << (*ir)->det()->geographicalId().det()
827  << " sub det " << (*ir)->det()->subDetector()<<endl;
828 
829  if ((*ir)->det()->geographicalId().det() == 2 && (*ir)->det()->subDetector() == 6) {
830 // const CSCRecHit2D* iCSC = dynamic_cast<const CSCRecHit2D*>(&**ir);
831 // if (iCSC) LogTrace(category_)<<"csc from cast tpeak "<<iCSC->tpeak();
832  CSCRecHit2DCollection::range thisrange = cschits_->get(CSCDetId((*ir)->geographicalId()));
833  for (CSCRecHit2DCollection::const_iterator rechit = thisrange.first; rechit!=thisrange.second;++rechit) {
834  if ((*rechit).isValid()) LogTrace(category_)<<"csc from collection tpeak "<<(*rechit).tpeak();
835  }
836  }
837  if ((*ir)->det()->geographicalId().det() == 2 && (*ir)->det()->subDetector() == 7) {
838 // const DTRecHit1D* iDT = dynamic_cast<const DTRecHit1D*>(&**ir);
839 // if (iDT) LogTrace(category_)<<"dt digitime "<<iDT->digiTime();
840  DTRecHitCollection::range thisrange = dthits_->get(DTLayerId((*ir)->geographicalId()));
841  for (DTRecHitCollection::const_iterator rechit = thisrange.first; rechit!=thisrange.second;++rechit) {
842  if ((*rechit).isValid()) LogTrace(category_)<<"dt from collection digitime "<<(*rechit).digiTime();
843  }
844  }
845  }
846 
847  return;
848 
849 }
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:52
T perp() const
Definition: PV3DBase.h:71
edm::Handle< CSCRecHit2DCollection > cschits_
edm::Handle< DTRecHitCollection > dthits_
ConstRecHitContainer recHits(bool splitting=false) const
Definition: Trajectory.cc:67
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:45
#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 895 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by build(), and trajectories().

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

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

Referenced by buildSecondHalf().

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

Definition at line 74 of file CosmicMuonTrajectoryBuilder.h.

References theNavigation.

Referenced by build(), and trajectories().

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

Definition at line 59 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 62 of file CosmicMuonTrajectoryBuilder.h.

References MuonServiceProxy::propagator(), and theService.

Referenced by build().

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

Definition at line 64 of file CosmicMuonTrajectoryBuilder.h.

References MuonServiceProxy::propagator(), and theService.

Referenced by build().

64 {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 693 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by buildSecondHalf().

693  {
694 
695  PropagationDirection newDir = (traj.firstMeasurement().recHit()->globalPosition().y()
696  < traj.lastMeasurement().recHit()->globalPosition().y())
698  Trajectory newTraj(traj.seed(), newDir);
699 
700  const std::vector<TrajectoryMeasurement>& meas = traj.measurements();
701 
702  for (std::vector<TrajectoryMeasurement>::const_reverse_iterator itm = meas.rbegin();
703  itm != meas.rend(); ++itm ) {
704  newTraj.push(*itm);
705  }
706  traj = newTraj;
707 
708 }
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:265
ConstRecHitPointer recHit() const
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 745 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by trajectories().

745  {
746 
747  if ( traj.direction() == anyDirection ) return;
749  Trajectory newTraj(traj.seed(), newDir);
750  const std::vector<TrajectoryMeasurement>& meas = traj.measurements();
751 
752  for (std::vector<TrajectoryMeasurement>::const_iterator itm = meas.begin(); itm != meas.end(); ++itm) {
753  newTraj.push(*itm);
754  }
755 
756  while (!traj.empty()) {
757  traj.pop();
758  }
759 
760  traj = newTraj;
761 
762 }
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:234
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:265
PropagationDirection
PropagationDirection const & direction() const
Definition: Trajectory.cc:195
DataContainer const & measurements() const
Definition: Trajectory.h:203
void pop()
Definition: Trajectory.cc:17
void CosmicMuonTrajectoryBuilder::selectHits ( MuonTransientTrackingRecHit::MuonRecHitContainer hits) const
private

Definition at line 613 of file CosmicMuonTrajectoryBuilder.cc.

References i, j, keep, and tmp.

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

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

Referenced by trajectories().

669  {
670 
672 
673  if (traj.empty()) return true;
674 
675  bool result = false;
676  for (ConstRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++ ) {
677  if ( !(*ir)->isValid() ) continue;
678  for (ConstRecHitContainer::const_iterator ir2 = ir+1; ir2 != hits.end(); ir2++ ) {
679  if ( !(*ir2)->isValid() ) continue;
680  if ( (*ir) == (*ir2) ) result = true;
681  }
682  }
683 
684  return result;
685 
686 }
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:234
ConstRecHitContainer recHits(bool splitting=false) const
Definition: Trajectory.cc:67
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 114 of file CosmicMuonTrajectoryBuilder.cc.

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

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

Definition at line 70 of file CosmicMuonTrajectoryBuilder.h.

References theSmoother.

Referenced by utilities().

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

Definition at line 912 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by checkDirectionByT0().

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

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

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

Definition at line 453 of file CosmicMuonTrajectoryBuilder.cc.

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

Referenced by trajectories().

453  {
454 
457  for (MuonRecHitContainer::const_iterator ihit = tmpHits.begin();
458  ihit != tmpHits.end(); ++ihit ) {
459  if ((*ihit)->geographicalId() != meas.recHit()->geographicalId() ){
460  result.push_back(*ihit);
461  LogTrace(category_) << "Unused hit: " << (*ihit)->globalPosition() << endl;
462  }
463  }
464 
465  return result;
466 
467 }
ConstRecHitPointer 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 66 of file CosmicMuonTrajectoryBuilder.h.

References theUpdator.

Referenced by build(), and trajectories().

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

Definition at line 72 of file CosmicMuonTrajectoryBuilder.h.

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

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

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

Member Data Documentation

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

Definition at line 139 of file CosmicMuonTrajectoryBuilder.h.

Referenced by getDirectionByTime().

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

Definition at line 140 of file CosmicMuonTrajectoryBuilder.h.

Referenced by getDirectionByTime().

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

Definition at line 138 of file CosmicMuonTrajectoryBuilder.h.

Referenced by CosmicMuonTrajectoryBuilder(), and setEvent().

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

Definition at line 118 of file CosmicMuonTrajectoryBuilder.h.

Referenced by CosmicMuonTrajectoryBuilder(), and setEvent().

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

Definition at line 129 of file CosmicMuonTrajectoryBuilder.h.

Referenced by CosmicMuonTrajectoryBuilder(), and propagator().

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

Definition at line 132 of file CosmicMuonTrajectoryBuilder.h.

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

bool CosmicMuonTrajectoryBuilder::theTraversingMuonFlag
private

Definition at line 131 of file CosmicMuonTrajectoryBuilder.h.

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

MuonTrajectoryUpdator* CosmicMuonTrajectoryBuilder::theUpdator
private