00001 #include "RecoMuon/L3TrackFinder/interface/MuonCkfTrajectoryBuilder.h"
00002
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004
00005 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00006 #include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h"
00007 #include "TrackingTools/PatternTools/interface/TrajMeasLessEstim.h"
00008 #include "RecoTracker/MeasurementDet/interface/MeasurementTracker.h"
00009 #include "TrackingTools/MeasurementDet/interface/LayerMeasurements.h"
00010 #include "TrackingTools/KalmanUpdators/interface/Chi2MeasurementEstimatorBase.h"
00011 #include "TrackingTools/TrajectoryFiltering/interface/TrajectoryFilter.h"
00012 #include "TrackingTools/PatternTools/interface/TransverseImpactPointExtrapolator.h"
00013
00014 #include <sstream>
00015
00016 MuonCkfTrajectoryBuilder::MuonCkfTrajectoryBuilder(const edm::ParameterSet& conf,
00017 const TrajectoryStateUpdator* updator,
00018 const Propagator* propagatorAlong,
00019 const Propagator* propagatorOpposite,
00020 const Propagator* propagatorProximity,
00021 const Chi2MeasurementEstimatorBase* estimator,
00022 const TransientTrackingRecHitBuilder* RecHitBuilder,
00023 const MeasurementTracker* measurementTracker,
00024 const TrajectoryFilter* filter):
00025 CkfTrajectoryBuilder(conf,updator,propagatorAlong,propagatorOpposite,estimator,RecHitBuilder,measurementTracker,filter),
00026 theProximityPropagator(propagatorProximity)
00027 {
00028
00029 theUseSeedLayer = conf.getParameter<bool>("useSeedLayer");
00030 theRescaleErrorIfFail = conf.getParameter<double>("rescaleErrorIfFail");
00031 }
00032
00033 MuonCkfTrajectoryBuilder::~MuonCkfTrajectoryBuilder()
00034 {}
00035
00036
00037 std::string dumpMeasurement(const TrajectoryMeasurement & tm)
00038 {
00039 std::stringstream buffer;
00040 buffer<<"layer pointer: "<<tm.layer()<<"\n"
00041 <<"estimate: "<<tm.estimate()<<"\n"
00042 <<"forward state: \n"
00043 <<"x: "<<tm.forwardPredictedState().globalPosition()<<"\n"
00044 <<"p: "<<tm.forwardPredictedState().globalMomentum()<<"\n"
00045 <<"geomdet pointer from rechit: "<<tm.recHit()->det()<<"\n"
00046 <<"detId: "<<tm.recHit()->geographicalId().rawId();
00047 if (tm.recHit()->isValid()){
00048 buffer<<"\n hit global x: "<<tm.recHit()->globalPosition()
00049 <<"\n hit global error: "<<tm.recHit()->globalPositionError().matrix()
00050 <<"\n hit local x:"<<tm.recHit()->localPosition()
00051 <<"\n hit local error"<<tm.recHit()->localPositionError();
00052 }
00053 return buffer.str();
00054 }
00055 std::string dumpMeasurements(const std::vector<TrajectoryMeasurement> & v)
00056 {
00057 std::stringstream buffer;
00058 buffer<<v.size()<<" total measurements\n";
00059 for (std::vector<TrajectoryMeasurement>::const_iterator it = v.begin(); it!=v.end();++it){
00060 buffer<<dumpMeasurement(*it);
00061 buffer<<"\n";}
00062 return buffer.str();
00063 }
00064
00065
00066 void MuonCkfTrajectoryBuilder::collectMeasurement(const DetLayer* layer,const std::vector<const DetLayer*>& nl,const TrajectoryStateOnSurface & currentState, std::vector<TM>& result,int& invalidHits, const Propagator * prop) const{
00067 for (std::vector<const DetLayer*>::const_iterator il = nl.begin();
00068 il != nl.end(); il++) {
00069
00070 TSOS stateToUse = currentState;
00071
00072 if (layer == (*il)){
00073 LogDebug("CkfPattern")<<" self propagating in findCompatibleMeasurements.\n from: \n"<<stateToUse;
00074
00075
00076 TransverseImpactPointExtrapolator middle;
00077 GlobalPoint center(0,0,0);
00078 stateToUse = middle.extrapolate(stateToUse, center, *prop);
00079
00080 if (!stateToUse.isValid()) continue;
00081 LogDebug("CkfPattern")<<"to: "<<stateToUse;
00082 }
00083
00084 std::vector<TM> tmp =
00085 theLayerMeasurements->measurements((**il),currentState, *prop, *theEstimator);
00086
00087 LogDebug("CkfPattern")<<tmp.size()<<" measurements returned by LayerMeasurements";
00088
00089 if ( !tmp.empty()) {
00090
00091
00092
00093
00094 if ( result.empty()) result = tmp;
00095 else {
00096
00097 result.insert( result.end()-invalidHits, tmp.begin(), tmp.end());
00098 }
00099 invalidHits++;
00100 }
00101 }
00102
00103 LogDebug("CkfPattern")<<"starting from:\n"
00104 <<"x: "<<currentState.globalPosition()<<"\n"
00105 <<"p: "<<currentState.globalMomentum()<<"\n"
00106 <<dumpMeasurements(result);
00107 }
00108
00109
00110
00111 void
00112 MuonCkfTrajectoryBuilder::findCompatibleMeasurements( const TempTrajectory& traj,
00113 std::vector<TrajectoryMeasurement> & result) const
00114 {
00115 int invalidHits = 0;
00116
00117
00118 std::vector<const DetLayer*> nl;
00119
00120 if (traj.empty())
00121 {
00122 LogDebug("CkfPattern")<<"using JR patch for no measurement case";
00123
00124
00125
00126 PTrajectoryStateOnDet ptod =traj.seed().startingState();
00127 DetId id(ptod.detId());
00128 const GeomDet * g = theMeasurementTracker->geomTracker()->idToDet(id);
00129 const Surface * surface=&g->surface();
00130 TrajectoryStateTransform tsTransform;
00131 TrajectoryStateOnSurface currentState(tsTransform.transientState(ptod,surface,theForwardPropagator->magneticField()));
00132
00133
00134 const DetLayer * l=theMeasurementTracker->geometricSearchTracker()->detLayer(id);
00135
00136 if (theUseSeedLayer){
00137 {
00138
00139 LogDebug("CkfPattern")<<"using the layer of the seed first.";
00140 nl.push_back(l);
00141 collectMeasurement(l,nl,currentState,result,invalidHits,theProximityPropagator);
00142 }
00143
00144
00145 if ((uint)invalidHits==result.size() && theRescaleErrorIfFail!=1.0 && result.size()!=0)
00146 {
00147 result.clear();
00148 LogDebug("CkfPattern")<<"using a rescale by "<< theRescaleErrorIfFail <<" to find measurements.";
00149 TrajectoryStateOnSurface rescaledCurrentState = currentState;
00150 rescaledCurrentState.rescaleError(theRescaleErrorIfFail);
00151 invalidHits=0;
00152 collectMeasurement(l,nl,rescaledCurrentState,result,invalidHits,theProximityPropagator);
00153 }
00154 }
00155
00156
00157 if (result.size()==0 || (uint)invalidHits==result.size())
00158 {
00159 result.clear();
00160 LogDebug("CkfPattern")<<"Need to go to next layer to get measurements";
00161
00162 nl = l->nextLayers(*currentState.freeState(), traj.direction());
00163 if (nl.size()==0){
00164 LogDebug("CkfPattern")<<" there was no next layer with wellInside. Use the next with no check.";
00165
00166
00167 nl = l->nextLayers(((traj.direction()==alongMomentum)?insideOut:outsideIn));
00168 }
00169 invalidHits=0;
00170 collectMeasurement(l,nl,currentState,result,invalidHits,theForwardPropagator);
00171 }
00172
00173
00174 if (result.size()!=0 && (uint)invalidHits==result.size() && theRescaleErrorIfFail!=1.0)
00175 {
00176 result.clear();
00177 LogDebug("CkfPattern")<<"using a rescale by "<< theRescaleErrorIfFail <<" to find measurements on next layers.";
00178 TrajectoryStateOnSurface rescaledCurrentState = currentState;
00179 rescaledCurrentState.rescaleError(theRescaleErrorIfFail);
00180 invalidHits=0;
00181 collectMeasurement(l,nl,rescaledCurrentState, result,invalidHits,theForwardPropagator);
00182 }
00183
00184 }
00185 else
00186 {
00187
00188 TSOS currentState( traj.lastMeasurement().updatedState());
00189
00190 nl = traj.lastLayer()->nextLayers( *currentState.freeState(), traj.direction());
00191 if (nl.empty()){LogDebug("CkfPattern")<<" no next layers... going "<<traj.direction()<<"\n from: \n"<<currentState<<"\n from detId: "<<traj.lastMeasurement().recHit()->geographicalId().rawId(); return ;}
00192
00193 collectMeasurement(traj.lastLayer(),nl,currentState,result,invalidHits,theForwardPropagator);
00194 }
00195
00196
00197
00198 if ( result.size() > 1) {
00199 sort( result.begin(), result.end()-invalidHits, TrajMeasLessEstim());
00200 }
00201
00202 #ifdef DEBUG_INVALID
00203 bool afterInvalid = false;
00204 for (std::vector<TM>::const_iterator i=result.begin();
00205 i!=result.end(); i++) {
00206 if ( ! i->recHit().isValid()) afterInvalid = true;
00207 if (afterInvalid && i->recHit().isValid()) {
00208 edm::LogError("CkfPattern") << "CkfTrajectoryBuilder error: valid hit after invalid!" ;
00209 }
00210 }
00211 #endif
00212
00213
00214
00215 }
00216
00217