Go to the documentation of this file.00001
00016 #include "RecoMuon/TrackingTools/interface/MuonBestMeasurementFinder.h"
00017
00018 #include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h"
00019 #include "RecoMuon/TransientTrackingRecHit/interface/MuonTransientTrackingRecHit.h"
00020
00021 #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
00022 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
00023 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
00024 #include "TrackingTools/KalmanUpdators/interface/Chi2MeasurementEstimator.h"
00025
00026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00027
00028
00029 using namespace std;
00030
00031 MuonBestMeasurementFinder::MuonBestMeasurementFinder(){
00032
00033 theEstimator = new Chi2MeasurementEstimator(100000.);
00034 }
00035
00036 MuonBestMeasurementFinder::~MuonBestMeasurementFinder(){
00037 delete theEstimator;
00038 }
00039
00040 TrajectoryMeasurement*
00041 MuonBestMeasurementFinder::findBestMeasurement(std::vector<TrajectoryMeasurement>& measC,
00042 const Propagator* propagator){
00043
00044 const std::string metname = "Muon|RecoMuon|MuonBestMeasurementFinder";
00045
00046 TMContainer validMeasurements;
00047
00048 TrajectoryMeasurement* bestMeasurement=0;
00049
00050
00051 int NumValidMeas=0;
00052 for ( vector<TrajectoryMeasurement>::iterator measurement = measC.begin();
00053 measurement!= measC.end(); ++measurement ) {
00054 if ((*measurement).recHit()->isValid()) {
00055 ++NumValidMeas;
00056 bestMeasurement = &(*measurement);
00057 validMeasurements.push_back( &(*measurement) );
00058 }
00059 }
00060
00061
00062
00063 if(NumValidMeas<=1) {
00064 LogTrace(metname) << "MuonBestMeasurement: just " << NumValidMeas
00065 << " valid measurement ";
00066 return bestMeasurement;
00067 }
00068
00069 TMIterator measurement;
00070 double minChi2PerNDoF=1.E6;
00071
00072
00073 for ( measurement = validMeasurements.begin(); measurement!= validMeasurements.end(); measurement++ ) {
00074
00075 TransientTrackingRecHit::ConstRecHitPointer muonRecHit = (*measurement)->recHit();
00076
00077
00078 pair<double,int> chi2Info = lookAtSubRecHits(*measurement, propagator);
00079
00080 double chi2PerNDoF = chi2Info.first/chi2Info.second;
00081 LogTrace(metname) << " The measurement has a chi2/npts " << chi2PerNDoF << " with dof = " << chi2Info.second
00082 << " \n Till now the best chi2 is " << minChi2PerNDoF;
00083
00084 if ( chi2PerNDoF && chi2PerNDoF<minChi2PerNDoF ) {
00085 minChi2PerNDoF = chi2PerNDoF;
00086 bestMeasurement = *measurement;
00087 }
00088
00089 }
00090 LogTrace(metname)<<"The final best chi2 is "<<minChi2PerNDoF<<endl;
00091 return bestMeasurement;
00092 }
00093
00094
00095 pair<double,int> MuonBestMeasurementFinder::lookAtSubRecHits(TrajectoryMeasurement* measurement,
00096 const Propagator* propagator){
00097
00098 const std::string metname = "Muon|RecoMuon|MuonBestMeasurementFinder";
00099
00100 unsigned int npts=0;
00101
00102
00103 TransientTrackingRecHit::ConstRecHitPointer muonRecHit = measurement->recHit();
00104 TrajectoryStateOnSurface predState = measurement->predictedState();
00105 std::pair<bool, double> sing_chi2 = estimator()->estimate( predState, *(muonRecHit.get()));
00106 npts = 1;
00107 std::pair<double, int> result = pair<double, int>(sing_chi2.second, npts);
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 return result;
00138 }