CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/RecoMuon/StandAloneTrackFinder/src/StandAloneMuonRefitter.cc

Go to the documentation of this file.
00001 
00010 #include "RecoMuon/StandAloneTrackFinder/interface/StandAloneMuonRefitter.h"
00011 
00012 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
00013 
00014 #include "TrackingTools/TrackFitters/interface/TrajectoryFitter.h"
00015 
00016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00018 #include "FWCore/Framework/interface/EventSetup.h"
00019 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00020 
00021 using namespace edm;
00022 using namespace std;
00023 
00024 StandAloneMuonRefitter::StandAloneMuonRefitter(const ParameterSet& par, const MuonServiceProxy* service):theService(service) {
00025   LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "Constructor called." << endl;
00026 
00027   theFitterName = par.getParameter<string>("FitterName");
00028   theNumberOfIterations = par.getParameter<unsigned int>("NumberOfIterations");
00029   isForceAllIterations = par.getParameter<bool>("ForceAllIterations");
00030   theMaxFractionOfLostHits = par.getParameter<double>("MaxFractionOfLostHits");
00031   errorRescale = par.getParameter<double>("RescaleError");
00032 }
00033 
00035 StandAloneMuonRefitter::~StandAloneMuonRefitter() {
00036   LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "Destructor called." << endl;
00037 }
00038 
00039   // Operations
00040 
00042 StandAloneMuonRefitter::RefitResult StandAloneMuonRefitter::singleRefit(const Trajectory& trajectory) {
00043   
00044   theService->eventSetup().get<TrajectoryFitter::Record>().get(theFitterName, theFitter);
00045 
00046   vector<Trajectory> refitted;
00047 
00048   TrajectoryMeasurement lastTM = trajectory.lastMeasurement();                                      
00049 
00050   TrajectoryStateOnSurface firstTsos(lastTM.updatedState());
00051 
00052   // Rescale errors before refit, not to bias the result
00053   firstTsos.rescaleError(errorRescale);
00054 
00055   TransientTrackingRecHit::ConstRecHitContainer trajRH = trajectory.recHits();                      
00056   reverse(trajRH.begin(),trajRH.end());                                                             
00057   refitted = theFitter->fit(trajectory.seed(), trajRH, firstTsos);                                  
00058 
00059   if(!refitted.empty()) return RefitResult(true,refitted.front());
00060   else return RefitResult(false,trajectory);
00061 }
00062 
00063 
00064 StandAloneMuonRefitter::RefitResult StandAloneMuonRefitter::refit(const Trajectory& trajectory) {
00065 
00066   LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "---------------------------------" << endl;
00067   LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "Starting refitting loop:" << endl;
00068 
00069   unsigned int nSuccess=0;
00070   unsigned int nOrigHits=trajectory.recHits().size();
00071   Trajectory lastFitted=trajectory;
00072   bool allIter=true;
00073   bool enoughRH=true;
00074 
00075   for(unsigned int j=0; j<theNumberOfIterations; ++j) {
00076 
00077     StandAloneMuonRefitter::RefitResult singleRefitResult = singleRefit(lastFitted);
00078     lastFitted = singleRefitResult.second;
00079     unsigned int nLastHits=lastFitted.recHits().size();
00080 
00081     if(!singleRefitResult.first) {
00082       allIter=false;
00083       LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "  refit n. " << nSuccess+1 << ": failed" << endl;
00084       break;
00085     }
00086 
00087     double lostFract= 1 - double(nLastHits)/nOrigHits;
00088     if(lostFract>theMaxFractionOfLostHits) {
00089       enoughRH=false;
00090       LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "  refit n. " << nSuccess+1 << ": too many RH lost" << endl;
00091       LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "     Survived RecHits: " << nLastHits << "/" << nOrigHits << endl;
00092       break;
00093     }
00094 
00095     nSuccess++;
00096     LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "  refit n. " << nSuccess << ": OK" << endl;
00097     LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << "     Survived RecHits: " << nLastHits << "/" << nOrigHits << endl;
00098 
00099   } // end for
00100 
00101   LogDebug("Muon|RecoMuon|StandAloneMuonRefitter") << nSuccess << " successful refits!" << endl;
00102 
00103   // if isForceAllIterations==true  =>   3 successful refits: (true, refitted trajectory)
00104   //                                    <3 successful refits: (false, original trajectory)
00105   // if isForceAllIterations==false =>  >0 successful refits: (true, last refitted trajectory)
00106   //                                     0 successful refits: (false, original trajectory)
00107   if(!enoughRH)
00108     return RefitResult(false, trajectory);
00109   else if(isForceAllIterations)
00110     return allIter ? RefitResult(allIter, lastFitted) : RefitResult(allIter, trajectory);
00111   else
00112     return nSuccess==0 ? RefitResult(false, trajectory) : RefitResult(true, lastFitted);
00113 }