46 : theService(service) {
49 bool enableDTMeasurement = par.
getParameter<
bool>(
"EnableDTMeasurement");
50 bool enableCSCMeasurement = par.
getParameter<
bool>(
"EnableCSCMeasurement");
51 bool enableRPCMeasurement = par.
getParameter<
bool>(
"EnableRPCMeasurement");
101 category_ =
"Muon|RecoMuon|CosmicMuon|CosmicMuonTrajectoryBuilder";
136 vector<Trajectory*> trajL = vector<Trajectory*>();
141 DetId did(ptsd1.detId());
151 vector<const DetLayer*> navLayers;
163 LogTrace(
category_) <<
"found " << navLayers.size() <<
" compatible DetLayers for the Seed";
165 if (navLayers.empty())
168 vector<DetWithState> detsWithStates;
170 for (vector<const DetLayer*>::const_iterator layer = navLayers.begin(); layer != navLayers.end(); layer++) {
171 LogTrace(
category_) << debug.dumpMuonId((*layer)->basicComponents().front()->geographicalId())
172 << debug.dumpLayer(*layer);
176 LogTrace(
category_) <<
"Number of compatible dets: " << detsWithStates.size() << endl;
178 if (!detsWithStates.empty()) {
180 if (detsWithStates.front().second.isValid()) {
182 LogTrace(
category_) << debug.dumpMuonId(detsWithStates.front().first->geographicalId())
183 << debug.dumpLayer(navLayers.front());
184 lastTsos = detsWithStates.front().second;
189 detsWithStates.clear();
211 int DTChamberUsedBack = 0;
212 int CSCChamberUsedBack = 0;
213 int RPCChamberUsedBack = 0;
214 int TotalChamberUsedBack = 0;
216 vector<TrajectoryMeasurement> measL;
220 for (vector<const DetLayer*>::const_iterator rnxtlayer = navLayers.begin(); rnxtlayer != navLayers.end();
224 LogTrace(
category_) << debug.dumpMuonId((*rnxtlayer)->basicComponents().front()->geographicalId())
225 << debug.dumpLayer(*rnxtlayer);
230 if (measL.empty() && (fabs(
theService->magneticField()->inTesla(
GlobalPoint(0, 0, 0)).z()) < 0.01) &&
231 (
theService->propagator(
"StraightLinePropagator").isValid())) {
239 for (vector<TrajectoryMeasurement>::const_iterator theMeas = measL.begin(); theMeas != measL.end(); ++theMeas) {
245 (*rnxtlayer), DTChamberUsedBack, CSCChamberUsedBack, RPCChamberUsedBack, TotalChamberUsedBack);
246 secondLast = lastTsos;
247 if ((!theTraj->
empty()) && result.second.isValid()) {
248 lastTsos = result.second;
251 }
else if ((theMeas)->predictedState().isValid())
252 lastTsos = (theMeas)->predictedState();
257 while (!theTraj->
empty()) {
261 if (!theTraj->
isValid() || TotalChamberUsedBack < 2 || (DTChamberUsedBack + CSCChamberUsedBack) == 0 ||
269 DTChamberUsedBack = 0;
270 CSCChamberUsedBack = 0;
271 RPCChamberUsedBack = 0;
272 TotalChamberUsedBack = 0;
282 if (lastPos.basicVector().dot(momDir.
basicVector()) > 0) {
298 LogTrace(
category_) <<
"Begin backward refitting, with " << navLayers.size() <<
" layers" << endl;
300 for (vector<const DetLayer*>::const_iterator rnxtlayer = navLayers.begin(); rnxtlayer != navLayers.end();
308 for (MuonRecHitContainer::const_iterator ihit = tmpHits.begin(); ihit != tmpHits.end(); ++ihit) {
309 allUnusedHits.push_back(*ihit);
314 for (vector<TrajectoryMeasurement>::const_iterator theMeas = measL.begin(); theMeas != measL.end(); ++theMeas) {
316 if (rnxtlayer != navLayers.begin()) {
317 vector<const DetLayer*>::const_iterator lastlayer = rnxtlayer;
320 if ((*rnxtlayer)->location() != (*lastlayer)->location()) {
322 GlobalPoint thisPos = (theMeas)->predictedState().globalPosition();
326 if (momDir.
mag() > 0.01) {
335 (lastTsos.
globalPosition().
z() * (theMeas)->predictedState().globalPosition().z() < 0)) {
345 if (bkresult.first) {
347 (*rnxtlayer), DTChamberUsedBack, CSCChamberUsedBack, RPCChamberUsedBack, TotalChamberUsedBack);
351 allUnusedHits.insert(allUnusedHits.end(), tmpUnusedHits.begin(), tmpUnusedHits.end());
353 if ((!myTraj.
empty()) && bkresult.second.isValid())
354 lastTsos = bkresult.second;
355 else if ((theMeas)->predictedState().isValid())
356 lastTsos = (theMeas)->predictedState();
361 for (vector<Trajectory*>::iterator
t = trajL.begin();
t != trajL.end(); ++
t)
367 (DTChamberUsedBack + CSCChamberUsedBack) < 1) {
397 if (!smoothed.empty() && smoothed.front().foundHits() > 3) {
399 myTraj = smoothed.front();
434 myTraj.
measurements().front().recHit()->globalPosition();
445 << myTraj.
measurements().back().updatedState().globalMomentum() << endl;
447 << myTraj.
measurements().front().updatedState().globalMomentum() << endl;
457 if (dir != propDir) {
476 for (MuonRecHitContainer::const_iterator ihit = tmpHits.begin(); ihit != tmpHits.end(); ++ihit) {
477 if ((*ihit)->geographicalId() != meas.
recHit()->geographicalId()) {
478 result.push_back(*ihit);
499 vector<const DetLayer*> navLayers;
524 if (navLayers.empty())
529 int DTChamberUsedBack = 0;
530 int CSCChamberUsedBack = 0;
531 int RPCChamberUsedBack = 0;
532 int TotalChamberUsedBack = 0;
545 vector<TrajectoryMeasurement> measL;
546 for (vector<const DetLayer*>::const_iterator rnxtlayer = navLayers.begin(); rnxtlayer != navLayers.end();
554 for (vector<TrajectoryMeasurement>::const_iterator theMeas = measL.begin(); theMeas != measL.end(); ++theMeas) {
556 if (bkresult.first) {
560 (*rnxtlayer), DTChamberUsedBack, CSCChamberUsedBack, RPCChamberUsedBack, TotalChamberUsedBack);
562 if ((!traj.
empty()) && bkresult.second.isValid())
563 lastTsos = bkresult.second;
564 else if ((theMeas)->predictedState().isValid())
565 lastTsos = (theMeas)->predictedState();
613 if (predTsos.isValid())
614 LogTrace(
category_) <<
"intermediateState: a intermediate state: pos: " << predTsos.globalPosition()
615 <<
"mom: " << predTsos.globalMomentum();
628 vector<bool>
keep(hits.size(),
true);
632 for (MuonRecHitContainer::const_iterator ihit = hits.begin(); ihit != hits.end(); ++ihit) {
638 for (MuonRecHitContainer::const_iterator ihit2 = ihit + 1; ihit2 != hits.end(); ++ihit2) {
643 if ((*ihit)->geographicalId() == (*ihit2)->geographicalId()) {
644 if ((*ihit)->dimension() > (*ihit2)->dimension()) {
646 }
else if ((*ihit)->dimension() < (*ihit2)->dimension()) {
649 if ((*ihit)->transientHits().size() > (*ihit2)->transientHits().size()) {
651 }
else if ((*ihit)->transientHits().size() < (*ihit2)->transientHits().size()) {
653 }
else if ((*ihit)->degreesOfFreedom() != 0 && (*ihit2)->degreesOfFreedom() != 0) {
654 if (((*ihit)->chi2() / (*ihit)->degreesOfFreedom()) > ((*ihit2)->chi2() / (*ihit)->degreesOfFreedom()))
667 for (MuonRecHitContainer::const_iterator ihit = hits.begin(); ihit != hits.end(); ++ihit) {
669 tmp.push_back(*ihit);
689 for (ConstRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++) {
690 if (!(*ir)->isValid())
692 for (ConstRecHitContainer::const_iterator ir2 = ir + 1; ir2 != hits.end(); ir2++) {
693 if (!(*ir2)->isValid())
722 std::vector<TrajectoryMeasurement>
const& meas = traj.
measurements();
723 for (
auto itm = meas.rbegin(); itm != meas.rend(); ++itm) {
745 if (refittedback.empty()) {
749 LogTrace(
category_) <<
"flipTrajectory: first " << refittedback.front().firstMeasurement().updatedState()
750 <<
"\nflipTrajectory: last " << refittedback.front().lastMeasurement().updatedState();
752 traj = refittedback.front();
765 const std::vector<TrajectoryMeasurement>& meas = traj.
measurements();
767 for (std::vector<TrajectoryMeasurement>::const_iterator itm = meas.begin(); itm != meas.end(); ++itm) {
771 while (!traj.
empty()) {
803 if (!refitted.empty())
804 traj = refitted.front();
810 if (!refittedback.empty())
811 traj = refittedback.front();
823 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++) {
824 if (!(*ir)->isValid()) {
830 LogTrace(
category_) <<
"pos" << pos <<
"radius " << pos.
perp() <<
" dim " << (*ir)->dimension() <<
" det " 831 << (*ir)->det()->geographicalId().det() <<
" sub det " << (*ir)->det()->subDetector() << endl;
833 if ((*ir)->det()->geographicalId().det() == 2 && (*ir)->det()->subDetector() == 6) {
838 if ((*rechit).isValid())
842 if ((*ir)->det()->geographicalId().det() == 2 && (*ir)->det()->subDetector() == 7) {
847 if ((*rechit).isValid())
864 std::vector<TrajectoryMeasurement>
result;
865 std::vector<TrajectoryMeasurement> measurements;
868 std::vector<TrajectoryMeasurementGroup> measurementGroups =
871 for (std::vector<TrajectoryMeasurementGroup>::const_iterator tmGroupItr = measurementGroups.begin();
872 tmGroupItr != measurementGroups.end();
874 measurements = tmGroupItr->measurements();
879 result.push_back(*bestMeasurement);
887 result.push_back(*bestMeasurement);
889 measurements.clear();
898 const DetLayer* layer,
int& dtChambers,
int& cscChambers,
int& rpcChambers,
int& totalChambers) {
913 if ((dtseg ==
nullptr) || (!dtseg->
hasPhi()))
940 if (dtseg1 == dtseg2 ||
t0(dtseg1) ==
t0(dtseg2))
bool empty() const
True if trajectory has no measurements.
void rescaleError(double factor)
void reverseTrajectoryPropagationDirection(Trajectory &) const
reverse the propagation direction of a trajectory
T getParameter(std::string const &) const
const Propagator * propagator() const
double t0(const DTRecSegment4D *deseg) const
std::pair< const_iterator, const_iterator > range
iterator range
TrajectoryStateOnSurface const & predictedState() const
const MeasurementEstimator * estimator() const
accasso at the propagator
ConstRecHitPointer const & recHit() const
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
std::vector< const DetLayer * > compatibleEndcapLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection) const
CosmicMuonSmoother * theSmoother
void estimateDirection(Trajectory &) const
check the direction of trajectory by checking eta spread
void makeFirstTime()
reset the theFirstTSOSFlag
TrajectoryStateOnSurface intermediateState(const TrajectoryStateOnSurface &) const
edm::Handle< CSCRecHit2DCollection > cschits_
virtual SubDetector subDetector() const =0
The type of detector (PixelBarrel, PixelEndcap, TIB, TOB, TID, TEC, CSC, DT, RPCBarrel, RPCEndcap)
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
unsigned long long theCacheId_DG
Global3DPoint GlobalPoint
MuonTrajectoryUpdator * backwardUpdator() const
GlobalPoint globalPosition() const
ConstRecHitContainer recHits() const
MuonCandidate::TrajectoryContainer TrajectoryContainer
std::string thePropagatorName
edm::Handle< DTRecHitCollection > dthits_
const Propagator * propagatorOpposite() const
void setEvent(const edm::Event &) override
pass the Event to the algo at each event
MuonDetLayerMeasurements * theLayerMeasurements
bool theTraversingMuonFlag
const CosmicMuonUtilities * utilities() const
DirectMuonNavigation * theNavigation
std::vector< TrajectoryMeasurementGroup > groupedMeasurements(const DetLayer *layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est, const edm::Event &iEvent)
std::vector< Trajectory * > trajectories(const TrajectorySeed &) override
build trajectories from seed
std::vector< const DetLayer * > compatibleLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection) const
PropagationDirection const & direction() const
C::const_iterator const_iterator
constant access iterator type
DataContainer const & measurements() const
DirectMuonNavigation * navigation() const
void flipTrajectory(Trajectory &) const
flip a trajectory with refit (the momentum direction is opposite)
MuonTrajectoryUpdator * updator() const
MuonRecHitContainer recHits(const DetLayer *layer, const edm::Event &iEvent)
returns the rechits which are on the layer
void reverseTrajectory(Trajectory &) const
reverse a trajectory without refit (out the measurements order changed)
MuonBestMeasurementFinder * theBestMeasurementFinder
void setFitDirection(NavigationDirection fitDirection)
set fit direction
TrajectoryMeasurement const & lastMeasurement() const
FreeTrajectoryState const * freeState(bool withErrors=true) const
MuonTrajectoryUpdator * theBKUpdator
void incrementChamberCounters(const DetLayer *layer, int &dtChambers, int &cscChambers, int &rpcChambers, int &totalChambers)
bool hasPhi() const
Does it have the Phi projection?
~CosmicMuonTrajectoryBuilder() override
Destructor.
MeasurementContainer measurements(const DetLayer *layer, const GeomDet *det, const TrajectoryStateOnSurface &stateOnDet, const MeasurementEstimator &est, const edm::Event &iEvent)
GlobalVector momentum() const
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
std::vector< ConstRecHitPointer > ConstRecHitContainer
void getDirectionByTime(Trajectory &) const
check the direction of trajectory by checking the timing
GlobalPoint position() const
PropagationDirection checkDirectionByT0(const DTRecSegment4D *, const DTRecSegment4D *) const
TrajectoryMeasurement const & firstMeasurement() const
PTrajectoryStateOnDet const & startingState() const
std::vector< Trajectory > fit(const Trajectory &) const
edm::ParameterSet theNavigationPSet
MuonTrajectoryUpdator * theUpdator
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
const MuonServiceProxy * theService
void selectHits(MuonTransientTrackingRecHit::MuonRecHitContainer &) const
void setEvent(const edm::Event &)
set event
GlobalVector globalMomentum() const
CosmicMuonTrajectoryBuilder(const edm::ParameterSet &, const MuonServiceProxy *service, edm::ConsumesCollector &iC)
Constructor.
const Propagator * propagatorAlong() const
TrajectoryMeasurement * findBestMeasurement(std::vector< TrajectoryMeasurement > &measC, const Propagator *propagator)
return the Tm with the best chi2: no cut applied.
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
std::vector< TrajectoryMeasurement > findBestMeasurements(const DetLayer *, const TrajectoryStateOnSurface &, const Propagator *, const MeasurementEstimator *)
virtual std::pair< bool, TrajectoryStateOnSurface > update(const TrajectoryMeasurement *measurement, Trajectory &trajectory, const Propagator *propagator)
update the Trajectory with the TrajectoryMeasurement
void buildSecondHalf(Trajectory &)
bool selfDuplicate(const Trajectory &) const
check if the trajectory iterates the same hit more than once
TrajectoryStateOnSurface const & updatedState() const
MuonTransientTrackingRecHit::MuonRecHitContainer unusedHits(const DetLayer *, const TrajectoryMeasurement &) const
double t0() const
Get the segment t0 (if recomputed, 0 is returned otherwise)
void reverseDirection(TrajectoryStateOnSurface &, const MagneticField *) const
void build(const TrajectoryStateOnSurface &, const NavigationDirection &, Trajectory &)
const BasicVectorType & basicVector() const
std::vector< MuonRecHitPointer > MuonRecHitContainer
TrajectoryContainer trajectories(const Trajectory &traj) const override
GlobalVector globalDirection() const
T dot(const Basic3DVector &rh) const
Scalar product, or "dot" product, with a vector of same type.