CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/RecoMuon/TrackingTools/src/MuonBestMeasurementFinder.cc

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   // consider only valid TM
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   // If we have just one (or zero) valid meas, return it at once 
00062   // (or return null measurement)
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   // if there are more than one valid measurement, then sort them.
00073   for ( measurement = validMeasurements.begin(); measurement!= validMeasurements.end(); measurement++ ) {
00074 
00075     TransientTrackingRecHit::ConstRecHitPointer muonRecHit = (*measurement)->recHit();
00076     
00077     // FIXME!! FIXME !! FIXME !!
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   // unused  double thisChi2 = 0.;
00102 
00103   TransientTrackingRecHit::ConstRecHitPointer muonRecHit = measurement->recHit();
00104   TrajectoryStateOnSurface predState = measurement->predictedState();                          // temporarily introduced by DT
00105   std::pair<bool, double> sing_chi2 = estimator()->estimate( predState, *(muonRecHit.get()));  // temporarily introduced by DT
00106   npts = 1;                                                                                    // temporarily introduced by DT
00107   std::pair<double, int> result = pair<double, int>(sing_chi2.second, npts);                   // temporarily introduced by DT
00108   
00109 //   // ask for the 2D-segments/2D-rechit                                                      // temporarily excluded by DT
00110 //   TransientTrackingRecHit::ConstRecHitContainer rhits_list = muonRecHit->transientHits();
00111   
00112 //   LogTrace(metname)<<"Number of rechits in the measurement rechit: "<<rhits_list.size()<<endl;
00113   
00114 //   // loop over them
00115 //   for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator rhit = rhits_list.begin();
00116 //        rhit!= rhits_list.end(); ++rhit)
00117 //     if ((*rhit)->isValid() ) {
00118 //       LogTrace(metname)<<"Rechit dimension: "<<(*rhit)->dimension()<<endl;
00119 //       npts+=(*rhit)->dimension();
00120       
00121 //       TrajectoryStateOnSurface predState;
00122       
00123 //       if (!( (*rhit)->geographicalId() == muonRecHit->geographicalId() ) ){
00124 //      predState = propagator->propagate(*measurement->predictedState().freeState(),
00125 //                                        (*rhit)->det()->surface()); 
00126 //       }
00127 //       else predState = measurement->predictedState();  
00128       
00129 //       if ( predState.isValid() ) { 
00130 //      std::pair<bool,double> sing_chi2 = estimator()->estimate( predState, *((*rhit).get()));
00131 //      thisChi2 += sing_chi2.second ;
00132 //      LogTrace(metname) << " single incremental chi2: " << sing_chi2.second;
00133 //       }
00134 //     }
00135   
00136 //   pair<double,int> result = pair<double,int>(thisChi2,npts);
00137   return result;
00138 }